So it seems (to me so far) that the Drupal 7 field theming is not compatible with contemplate, but I could use some help here and try to work around it.

$node is what we build the selectable/clickable items from, however for example, for images, $node->field_image contains "public://files/image.jpg" which needs to be processed further to get an image path, it cannot be themed the same way it did in D6

$node contains a lot of data for the fields which make it not possible to theme into contemplate directly without special handlers for every content field type

thoughts?

stdClass Object
(
    [vid] => 1
    [uid] => 1
    [title] => test
    [log] => 
    [status] => 1
    [comment] => 2
    [promote] => 1
    [sticky] => 0
    [nid] => 1
    [type] => test
    [language] => und
    [created] => 1316525027
    [changed] => 1316547629
    [tnid] => 0
    [translate] => 0
    [revision_timestamp] => 1316547629
    [revision_uid] => 1
    [body] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => test
                            [summary] => 
                            [format] => filtered_html
                            [safe_value] => <p>test</p>

                            [safe_summary] => 
                        )

                )

        )

    [field_list] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => one
                        )

                    [1] => Array
                        (
                            [value] => three
                        )

                )

        )

    [field_test] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [fid] => 2
                            [alt] => 
                            [title] => 
                            [uid] => 1
                            [filename] => Screenshot - 09202011 - 12:04:25 PM.png
                            [uri] => public://Screenshot - 09202011 - 12:04:25 PM.png
                            [filemime] => image/png
                            [filesize] => 73750
                            [status] => 1
                            [timestamp] => 1316526260
                            [rdf_mapping] => Array
                                (
                                )

                        )

                )

        )

    [field_term] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [tid] => 1
                            [taxonomy_term] => stdClass Object
                                (
                                    [tid] => 1
                                    [vid] => 1
                                    [name] => someterm
                                    [description] => 
                                    [format] => 
                                    [weight] => 0
                                    [vocabulary_machine_name] => tags
                                    [rdf_mapping] => Array
                                        (
                                            [rdftype] => Array
                                                (
                                                    [0] => skos:Concept
                                                )

                                            [name] => Array
                                                (
                                                    [predicates] => Array
                                                        (
                                                            [0] => rdfs:label
                                                            [1] => skos:prefLabel
                                                        )

                                                )

                                            [description] => Array
                                                (
                                                    [predicates] => Array
                                                        (
                                                            [0] => skos:definition
                                                        )

                                                )

                                            [vid] => Array
                                                (
                                                    [predicates] => Array
                                                        (
                                                            [0] => skos:inScheme
                                                        )

                                                    [type] => rel
                                                )

                                            [parent] => Array
                                                (
                                                    [predicates] => Array
                                                        (
                                                            [0] => skos:broader
                                                        )

                                                    [type] => rel
                                                )

                                        )

                                    [uri] => Array
                                        (
                                            [path] => taxonomy/term/1
                                            [options] => Array
                                                (
                                                    [entity_type] => taxonomy_term
                                                    [entity] => stdClass Object
 *RECURSION*
                                                )

                                        )

                                )

                        )

                )

        )

    [field_text] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => sometext
                            [format] => 
                            [safe_value] => sometext
                        )

                )

        )

    [rdf_mapping] => Array
        (
            [rdftype] => Array
                (
                    [0] => sioc:Item
                    [1] => foaf:Document
                )

            [title] => Array
                (
                    [predicates] => Array
                        (
                            [0] => dc:title
                        )

                )

            [created] => Array
                (
                    [predicates] => Array
                        (
                            [0] => dc:date
                            [1] => dc:created
                        )

                    [datatype] => xsd:dateTime
                    [callback] => date_iso8601
                )

            [changed] => Array
                (
                    [predicates] => Array
                        (
                            [0] => dc:modified
                        )

                    [datatype] => xsd:dateTime
                    [callback] => date_iso8601
                )

            [body] => Array
                (
                    [predicates] => Array
                        (
                            [0] => content:encoded
                        )

                )

            [uid] => Array
                (
                    [predicates] => Array
                        (
                            [0] => sioc:has_creator
                        )

                    [type] => rel
                )

            [name] => Array
                (
                    [predicates] => Array
                        (
                            [0] => foaf:name
                        )

                )

            [comment_count] => Array
                (
                    [predicates] => Array
                        (
                            [0] => sioc:num_replies
                        )

                    [datatype] => xsd:integer
                )

            [last_activity] => Array
                (
                    [predicates] => Array
                        (
                            [0] => sioc:last_activity_date
                        )

                    [datatype] => xsd:dateTime
                    [callback] => date_iso8601
                )

        )

    [cid] => 0
    [last_comment_timestamp] => 1316525027
    [last_comment_name] => 
    [last_comment_uid] => 1
    [comment_count] => 0
    [name] => admin
    [picture] => 0
    [data] => a:1:{s:7:"overlay";i:1;}
    [uri] => Array
        (
            [path] => node/1
            [options] => Array
                (
                    [entity_type] => node
                    [entity] => stdClass Object
 *RECURSION*
                )

        )

    [entity_view_prepared] => 1
)

Comments

Anonymous’s picture

Issue tags: +design decision

Hi !

Some quick thoughts about it…

Drupal 7 generates HTML code at the very last moment instead of what was done in Drupal 6 and earlier → Render arrays in Drupal 7

A ready to render array can be generated from the $node object via the node_view function → Drupal API : node_view

Should Contemplate give you a render array (instead of the $node object) in which you could create/modify/delete elements letting the rendering to the theme ?
Or is it up to you to render each elements via node_view and render in the template, thus generating HTML ?

Could Contemplate rely on token or dedicated data structure instead of internal Drupal structure ?

dgtlmoon’s picture

Well, it's kind of debatable if this module needs to be around any more at all..

we can use tokens i guess, but there was some ongoing issue with content/tokens/theme stuff atm

dgtlmoon’s picture

adding tag to this also

pwieck’s picture

This is probably not the place for this, but this module was my key to starting to learn the under hood workings of Drupal 6. I am a Drupal developer now and no longer use this module unless it is already being used on a current project, but couldn't imagine my out come without it.

I was saddened when I discover a site I ported over from D6 to D7 using Content Template had a large red banner in the admin area announcing it's removal.

I thank you for your module and sorry it doesn't seem to be going your way. For a long time during my crash course learning this was on my list of always install modules. It's great for an end user with little Drupal knowledge or FTP access to have professional looking and working cck layouts.

Thanks Again,
Paul

dgtlmoon’s picture

yes, it is heartbreaking to see the core drupal contributors not supporting this module (update: personal attack removed).

I will keep fighting on and trying to raise awareness of how important this module is and how unnacceptable these kinds of attitudes are.

Keep the comments like these coming! it helps to build a case!

designcontext’s picture

I totaly agree with pwieck!
Sad to see this module go - In my opinion it's important for non-developers who want to control the output.

Dave Reid’s picture

Has anyone looked at Display Suite (http://drupal.org/project/ds) yet? It seems like it might make a very good fit for people looking for a non-code display controlling module which actually works with the render API system.

kt226’s picture

It is really sad to see this module not supported. I count on it heavily for both D6 and D7. It gives me the flexibility to output the content they way I want without much hassle. I tried the Display Suite module before but I am not very impressed. Perhaps I need to give it another go.

dgtlmoon’s picture

@kt226 -> So it sounds like the thing people really need in this module is being able to SEE the HTML output and then tweak as you see fit, add classes, rearrange the structure into something bizzare etc

in D6 you get the PHP values so from this you can do whatever you like, but in D7 theres no way to get those values, really really annoying, the best thing i think we can do is use some tokens for the values instead and just 'make up' some HTML around those values, unlike D6 - this wont be a true representation of what Drupal is thinking/generating for the output..

So in summary, I don't know :(

mrmeech’s picture

I, too, am really saddened to see this project for D7 get removed. I feel the same exact way as pwieck in post #4, using contemplate to hunt down things i wanted to output/manipulate in a tmp.php file.

Really hope a solution can be worked out, as the module really has been such a help in getting off the ground as a Drupal developer. Unfortunately Dave's suggestion (comment #7) for Display Suite seems like it simply doesn't satisfy using contemplate in this manner.

PepeMty’s picture

+1 to pwieck. Although I'm still on the learning path, so I still rely on contemplate for, among other things, build custom tmp.php files for printing nodes + lots of cck fields that are not in the node.

Sad, really.

Warm regards from sunny México.

chx’s picture

I am happy to help this module but I need more explanation of what the problem is. Cant you use http://api.drupal.org/api/drupal/modules--node--node.api.php/function/ho... and apply #pre_render for example..?

ericras’s picture

My use case for wanting this module in D7 is the ability to modify tpl.php files (or a proxy for them - what Contemplate does) without access to the file system. My project is a very large multisite setup where the only access a site admin has to the file system is uploads to the files dir. The code base is handled through a multi-step subversion process and pushing tpl.php file additions and tweaks up to production for every site is not realistic.

I've been studying the code at its current 7.x-1.x status: http://drupalcode.org/project/contemplate.git/shortlog/refs/heads/7.x-1.x and I think it works pretty good. My first step was to replicate the normal output that you would get without using Contemplate.

Since Contemplate replaces the contents of the Body field; if you do this in Contemplate:

<?php $fields = field_attach_view('node', $node, 'full', 'en'); ?>
<?php print render($fields); ?>

you end up with the body field inside itself, a duplication of the body field wrappers:

<div class="node node-page node-promoted clearfix" id="node-37">
  <div class="content">
    <div class="field field-name-body field-type-text-with-summary field-label-hidden clearfix">
      <div class="field-items">
          <div class="field-item even">

            <div class="field field-name-body field-type-text-with-summary field-label-hidden clearfix">
              <div class="field-items">
                <div class="field-item even"><p>my body content</p></div>
              </div>
            </div>

            <div class="field field-name-field-blah field-type-text-long field-label-above clearfix">
              <div class="field-label">My Label</div>
                <div class="field-items">
                   <div class="field-item even"><p>my blah content</p></div>
                </div>
              </div>
            </div>

            etc...etc...etc...

</div></div></div></div></div>

But we could use a simple wrapper-free field--body.tpl.php template added when Contemplate is enabled:

<?php print render($item); ?>

that would allow this code in Contemplate to replicate the normal output:

<?php $fields = field_attach_view('node', $node, 'full', 'en'); ?>

<div class="field field-name-body field-type-text-with-summary field-label-hidden clearfix">
  <div class="field-items">
    <div class="field-item even">
      <?php print render($fields['body'][0]); ?>
    </div>
  </div>
</div>

<?php print render($fields['field_blah']); ?>

<?php print render($fields['field_images']); ?>

<?php print render($fields['field_myotherfield']); ?>

And then from there you can break it down further to really customize:

<?php $fields = field_attach_view('node', $node, 'full', 'en'); ?>

<div class="grid6 first">
  <?php print render($fields['field_images'][0]); ?>

  <div class="field field-name-body field-type-text-with-summary field-label-hidden clearfix">
    <div class="field-items">
      <div class="field-item even">
        <?php print render($fields['body'][0]); ?>
      </div>
    </div>
  </div>
</div>

<div class="grid6 last">
  <h1>Images from field_images in a loop, skipping the first</h1>
  <?php foreach($fields['field_images']['#items'] as $key=>$value) {
      if ($key !== 0) {
         print render($fields['field_images'][$key]);
      }
  } ?>
</div>

This essentially works for me. Now, I'm not familiar with Drupal 6 nor Contemplate for D6 so I'm not sure why this approach isn't suitable. I understand with using render() it is not backwards compatible as D6 just had the field html available in $node, but what else is the issue?

I'm also unclear what the purpose of having template files in a 'contemplates' directory is and having Contemplate scan for those and write them to {contemplate_files} in the database. If you can just put template files on the server why do you need this module?

One more issue is the fact that $GLOBALS is available. Granted, the people with permission to use this should be trusted but it would be preferable to not be able to do this in this module:

var_dump($GLOBALS['databases']);

giorgio79’s picture

@davereid: Has anyone looked at Display Suite (http://drupal.org/project/ds) yet? It seems like it might make a very good fit for people looking for a non-code display controlling module which actually works with the render API system.

I took a look at display suite, good stuff, but what I liked about contemplate is that it gave you complete control of the html output, and you were able to add totally custom html, inline css and javascript, or even do some last minute hacks on content with php before output...

jrglasgow’s picture

after reading through this thread a couple of times I decided to do something about it...

I adjusted the $node object to include the output of node_view() which includes all the build information that drupal_render() needs to render a field

I added this to my template and got the image to display like it should according to the settings.

<?php print drupal_render($node->build['field_image']); ?>

http://drupalcode.org/project/contemplate.git/commit/e274b89

I also added a preview button to load the node via ajax so you can preview the template changes without saving them.

dgtlmoon’s picture

Yup great, so now the template extract looks like..

  <div class="field field-type-image-image field-field-photo-image">
    <h3 class="field-label">image</h3>
    <div class="field-items">
        <div class="field-item"><?php print drupal_render($node->build['field_photo_image']); ?></div>
    </div>
  </div>

Do we need to include the wrapped HTML ? or just use the print drupal_render(...) ?

dgtlmoon’s picture

Problem is, if the template *only* has the print drupal_render(...) code then you still get this output

<div class="field field-name-field-photo-image field-type-image field-label-above">
  <div class="field-label">image:&nbsp;</div>
    <div class="field-items">
      <div class="field-item even"><img typeof="foaf:Image" src="http://d7.localhost/sites/default/files/styles/large/public/1326993893000.jpg" width="362" height="480" alt="">
      </div>
     </div>
  </div>

how do you edit this output like we used to in D6?

jrglasgow’s picture

Status: Active » Postponed (maintainer needs more info)

it all depends on what you want the output to be... do you have an example of what you want the output to be?

dgtlmoon’s picture

<div class="field field-name-field-photo-image field-type-image field-label-above">
  
    <div class="field-items  extracss">
      <div class="field-item even"><img typeof="foaf:Image" src="http://d7.localhost/sites/default/files/styles/large/public/1326993893000.jpg" width="362" height="480" alt="" class="foo">
      </div>
      <div class="thing">
        the strange thing strcture

      </div>
  
  </div>
ahansen1’s picture

Subscribing.

Like others, I also need to generate field output themed by the widget, but without the field wrapper div's. Meaning, if an image is being output as shown in post #19, I would need only the image tag itself and none of the "field-*" div structure. I want to control the structure myself.

<img typeof="foaf:Image" src="http://d7.localhost/sites/default/files/styles/large/public/1326993893000.jpg" width="362" height="480" alt="" class="foo">

EDITED: Forgot to wrap my img snippet in code.

ahansen1’s picture

I don't know if anyone else will find this helpful, but I was able to get what I wanted (right after I posted of course) using the array index instead of the array itself, e.g.

<?php $fields = field_attach_view('node', $node, 'full', 'en'); ?>
image: <?php print render($fields['field_image'][0]); ?>
jrglasgow’s picture

just take the uri "public://files/image.jpg" that you are given and send it to file_create_url()

print file_create_url('public://files/image.jpg');

the file_create_url() function will take the public/private uri and return a url

dgtlmoon’s picture

@jrglasgow ok so for every file reference i should print this out in the template?

thoughtcat’s picture

I am also disappointed to see that this terrific module may become obsolete in D7. As a non-coder, one of the first things I did when I first built a Drupal site was look at the way my content was arranged all over the page and wonder "how on earth do I get it to look the way I want it to look?" I was amazed, actually, that there wasn't an easier way to modify the output of a node within the existing system, and I tore my hair out until someone pointed me toward Contemplate. I was then able to build up my nodes exactly how I wanted them to look. As someone else said above, this has always been on my list of essential modules and I really hope the problem can be worked out.

Danny Englander’s picture

I've always used this module simply for the code and then I pop it into a custom node tpl file. I just tried this for the first time for Drupal 7 and it worked just like I used it in Drupal 6 with the code >> template approach.

I did not need to alter any output at all, I simply copied the code from the textbox once I checked "Affect body output". Hopefully this will help anyone wishing to use this method rather then the database method. I can offer more help here if anyone needs it.

twood’s picture

As a Drupal developer that is more of a designer/HTML/CSS guy that has built over 40 Drupal sites, I have also relied on my most favorite "Contemplates" module for theming and designing pages/nodes within Drupal 6. I used it to create unique looks for Content Types within an overall style/theme. That allowed me to create interfaces for clients with very specific fields and then arrange and stylize those elements- exactly as I wanted to.

I'm now learning D7 theming and looking for ways of doing this without Contemplates since I fear it is on the way out. Although I have gotten used to it, I also trust the Drupal creators in their wisdom and feel there is probably a better way of doing what I was doing, using a newer method within the D7 application. I am also now involved in a rather large multisite project where several D6 sites will become D7- so it's trial by fire for me.

I will look into Display Suite.

Actually just found Article Templater that may be helpful- am planning to check it out further.

Good luck everyone-

Anonymous’s picture

After reading this, I have to say it is sad.

I have waited for the many modules I use to stabilise in D7 so I could perform an upgrade, but I like many other have used, and relied on Contemplate for that fine structuring of a node, whether it be hiding fields from view, or adding rules for access rights to specific fields so only specific users can see them, or just applying a weird theme.

Not being able to do it easily with my skill level, just puts the nail in the coffin for D7 as far as I am concerned. So it will remain a D6 site as long as the server can handle it. And the 2 new sites I am about to start building, looks like they are going to be D6 too. I started at D4.7 and liked D6 very much. I am just getting too old to learn all these fancy new tricks, I want stability and continuity.

If a D7 version does one day get released, I will certainly look at it, but the hastle of changing the site from D6 is bad enough, and good enough reason to not change, and for me this is a show stopper.

chx’s picture

What if contemplate would pose as a subtheme of the current theme (hook_system_info_alter I would think) and would use a stream wrapper to read the templates from the database?

dgtlmoon’s picture

yes that could work, as it makes it focus on a different level, have todo some research

sonicthoughts’s picture

starting a D7 site, and although there is an rc3 version, I'm too nervous to depend on it. would be great to get a sense of the future of contemplate as it is a great tool for the light developer.