Closed (won't fix)
Project:
Content Templates (Contemplate)
Version:
5.x-2.01
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Apr 2008 at 15:04 UTC
Updated:
29 Jan 2009 at 21:51 UTC
I created a contemplate for a teaser. Those teasers are listed in a views block.
The text area with available teaser variables says that there is an array called 'links' available:
$node->links (array)
$node->links['node_read_more'] (array)
$node->links['node_read_more']['title']
Read more
$node->links['node_read_more']['href']
node/54
$node->links['node_read_more']['attributes'] (array)
$node->links['node_read_more']['attributes']['title']
Read the rest of this posting.
However, when I put the $node->links['node_read_more']['href'] in my template, it returns nothing. When I put <?php print_r($node) ?> in my template, it showed that the 'links' array isn't there at all. Any thoughts?
Comments
Comment #1
jrglasgow commentedNot all nodes will have the same variables, in the variables text area there is a sample node loaded. Even if all your node have links, they won't all have the same key is in the
$node->linksarray. The proper way to use contemplate to do something with your$node->linksIMO is using foreach (this is using the sample$node->linksyou give above):If you only wanted to do something with the 'node_read_more' link you would just do this:
To be able to help you in any other way I will need to know what you are doing with the links, maybe see the template you are setting up.
Comment #2
marcvangendjrglasgow, thanks for helping.
I want to create a block with teasers. However there will not be 'read more' links, but the complete teaser text will become a link to the complete article. My template looks like this:
So, I only need the links['node_read_more']['href'] variable.
The sample node which is loaded by contemplate (54) shows that there is a links array and the links['node_read_more']['href'] value is correct (see my first post). In the resulting block, the teaser of node #54 has become a link, but it links to my site root, because the path value passed to l() is empty.
Putting
<?php print_r($node) ?>in the template returns this:As you can see, the $links array isn't available at all.
Comment #3
jrglasgow commentedIt looks like the views module removes the links, or at least the 'read more' link. They want you to just click on the node title to get to the node. To do it the way you want to:
This works for my test site using the views teaser block.
Comment #4
marcvangendYou're right. This seems to be a bug in either contemplate or views (or is it by design? of just incompatibility?), but rather than trying to fix it, I'd better put the 'read more' link toghether myself and stop worrying.
Thanks for the help, I'm changing this to won't fix.
Comment #5
bartezz commentedI'd better put the 'read more' link toghether myself and stop worrying
I've encountered this problem as well and came here to find a solution. Although your solution works it might not be the best idea if one uses pathauto. Let's say the teaser you want to show is aimed at www.domain.com/news/drupal-is-cool but because $node->link isn't available you create a link based on nid www.domain.com/node/1. Although this points to the same page Google might encounter this as well, and a page like www.domain.com/node/1 isn't very SEO friendly. Much worse... Google somehow also found www.domain.com/news/drupal-is-cool.... duplicate content alert!!
I'll keep searching for a solution and post it if I'm able to come up with one.... please post yours as well!
Comment #6
acIf you want to solve your problem of duplicate URLs then use the drupal l() function which will automatically use any alias that may exist for the system path.
Comment #7
bartezz commentedThanx for the tip!
Comment #8
lias commentedBartezz would you mind posting your finished code for others (like me : ) to view? thanks.
Comment #9
bartezz commentedHi Isabug,
Sorry for the late reply, have to see if there is an notification by email option in this forum... :)
This is what I used:
Hope it works for you! Am a newcomer to Drupal so it might not be the best solution ;)
Cheers
Comment #10
tallsimon commentedtried in drupal 6 and it generated Fatal error: Unsupported operand types in ..../includes/common.inc on line 1546