0

I was wondering if its possible to setup a facility where I can attach content to existing content? Let me elaborate: I have my Page content type, but I want to give the content-editor the ability to add extra information which can be displayed in a separately styled <div>. (I do not want the editors playing around with the HTML.) This must be a zero-or-one relationship.

I'm thinking something like the nodereference_url module, except that I want to limit the amount of node references to a maximum of one. Does anyone how this can be achieved?

2
  • Are you using CCK?
    – mpdonadio
    Commented Oct 5, 2011 at 19:52
  • yes I am, and just setup views with views_attach in the hopes that I can get this to work.
    – maGz
    Commented Oct 5, 2011 at 19:59

1 Answer 1

2

This is actually pretty easy.

  1. Edit your content type (or clone to a new type). Add in a noderefernce CCK field as needed. Configure it for not mandatory, but limited to one value.

  2. Edit the fields for the type so that they are all hidden.

  3. Add a preprocess_node for your content type in template.php to read in the node relationship, theme the node, and then add it as a theme variable.

  4. Create a node template for your type.

  5. Edit the node template, to add in your div in the markup.

  6. Print out this theme variable in the node template.

This should get you down the right path.

4
  • Hi MPD and thanks. Could you expand a bit on your point #3? forgive this elementary question, but how would I go about coding this?
    – maGz
    Commented Oct 5, 2011 at 20:10
  • right now I have nodereference working where it can create 0 or 1 "attached" node, but on the Page node-type, it shows it as a link, instead of the full attached content
    – maGz
    Commented Oct 5, 2011 at 20:14
  • That is b/c of the #2 step above. Later tonight, I will rough out the #3 step for you.
    – mpdonadio
    Commented Oct 5, 2011 at 20:21
  • Thank you! I really appreciate you going out of your way to help me.
    – maGz
    Commented Oct 5, 2011 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.