0

Good Evening,

I'm using Drupal 6, CCK Module, and the Link Field Type. All are installed and activated.

I created a custom content type called Slider. A user can upload an image, a title, and a teaser. I created a custom field for that slider content type as well as one called Link with the field name: "field_link_test".

I created an entry, filled in all of the data including a URL for that link field type and clicked "Save". In views-view-table--slider.tpl.php, I added:

 <a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>

but on the front end, everything shows except for that link. I also tried emptying the Drupal cache.

Any ideas?

Update template code below, which all works fine, except for the new link value outputs nothing.

<div id="slider">
<div class="slider-holder">
    <?php foreach($rows as $row): ?>
    <div class="slide">
        <?php print $row['field_image_fid'] ?>
        <div class="info-slide">
            <h2><?php print $row['title'] ?></h2> 
            <p><?php print strip_tags($row['teaser']) ?></p>
            <a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
        </div><!--INFO-SLIDE-->
    </div><!--SLIDE--> 
    <?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">

</div>
</div><!--SLIDER-->
TechRemarker
  • 2,788
  • 11
  • 37
  • 60

3 Answers3

1

The easy possibilities (which you've probably checked, but just to get them out of the way):

  • you need to allow the field to be viewable by anonymous/authenticated users in User Management - Permissions

Otherwise, it's hard to tell without some code to analyse. Could you post your entire views-view-table--slide.tpl.php and if possible, your exported view or a link to the exported view?

EDIT

Now that I've had a chance to look at your view, I've made a couple of changes that should help.

The reason your link URL isn't showing is that you're including the "Node: Link" field in your View instead of the "Content: Link (field_link_test)" field. The first one will just link back to the original node rather than your custom link. Also, I don't think you can call the $node variable from views-view-table (at least, I don't get anything when I print it. Instead, you can use the $row variable.

I have a version of your template that prints out the URL in the field "link_test" with the label "Learn More." I put the "Learn More" text in the View itself as that'll be easier to edit and works better with the Link CCK type (which by default will want to add a title you add in the node edit screen).

The view export is here: http://pastebin.me/0ed2942f6953cb00cab1bd5386058a13. You can import this back into your site, but you may want to clone your original View first to make a backup, so that if this isn't what you want, you can use your old version.

The updated tpl is:

<div id="slider">
<div class="slider-holder">
    <?php foreach($rows as $row): ?>
    <div class="slide">
        <?php print $row['field_image_fid'] ?>
        <div class="info-slide">
            <h2><?php print $row['title'] ?></h2> 
            <p><?php print strip_tags($row['teaser']) ?></p>
            <?php print $row['field_link_test_url'] ?>
            <?php //print_r($row); ?>

        </div><!--INFO-SLIDE-->
    </div><!--SLIDE--> 
    <?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">

</div>
</div><!--SLIDER-->

Let me know if you have any issues/questions.

g_thom
  • 2,810
  • 2
  • 18
  • 18
  • @heavymark, you might not have the CCK submodule Content Permissions enabled. If it's enabled, you should see the options to set permissions for individual fields. hross' suggestion of adding some test code into your `views-view-table--slide.tpl.php` will help you see if the tpl is being picked up, at least. You can also always open your view and click on "Theme: Information" to see if your theme file is being read, to eliminate the possibility that your theme file is not being included. – g_thom Jun 06 '11 at 13:21
  • Enabled the content permissions and view for this new field but still no luck. Template does work fine and shows the slideshow, its just this one field that does not work. Add the "var_dump($node)" returns, "NULL". – TechRemarker Jun 06 '11 at 13:36
  • Can you see the field when you use `print_r($rows);` in the template file? – g_thom Jun 06 '11 at 13:42
  • No, it says, "Array ( [0] => Array ( [title] => Test Title [field_image_fid] => " – TechRemarker Jun 06 '11 at 13:53
  • @heavymark, would it be possible to export the view and share it with a tool like http://http://pastebin.me/? It's hard to know what's going on without seeing the internals. – g_thom Jun 06 '11 at 14:00
  • Which view would you like? The code for "views-view-table--slider.tpl.php" is in the post above. Let me know if you mean something else though. – TechRemarker Jun 06 '11 at 14:55
  • If you go to your view page and click on "Export," that should be it. If you can also export your CCK node, that will help too. – g_thom Jun 06 '11 at 15:01
  • When I go to "Views" the exported code for "slider" node is here http://pastebin.me/0ed2942f6953cb00cab1bd538602c58d – TechRemarker Jun 06 '11 at 15:12
  • When I go to Content Maangement > Slider item > Manage Fields I have (Label: Link2 Name: field_link_test Type: Link And in an actual slider content item I see that field and was able to save a URL such as http://google.com, but just missing something that will get it to show on the homepage. – TechRemarker Jun 06 '11 at 15:14
  • @heavymark - I've updated my answer with code - hope this is helpful for you. – g_thom Jun 07 '11 at 04:48
  • Those two things did it! I had used the row template tag you had but didn't have any luck. It appears the view code was my problem. I just need to figure out what you did differently so I can add another cck field on another part of my site. Thanks so much for your help! – TechRemarker Jun 07 '11 at 16:04
0

Are you sure the template is getting picked up (add <p>heavymark</p> above the href... does it show up?)?

If above shows up, add a var_dump($node) above the anchor tag and post the output so we can get a better idea of what's there (you probably want to enable XDebug so you get better formatted output, if its not on already).

hross
  • 3,633
  • 2
  • 27
  • 31
0

Make sure you add the link field to the view in the fields section. This should allow it to be themeable from within your template file. If you are still not seeing it, try using

print_r($rows,1);

or some variable of print_r to view all the rows that are available to be themed.

smthomas3
  • 121
  • 6
  • So under Views > Slider Item > Under Fields > I was able to add the new link field. Now what would be the code used to render that url in my template? This doesnt work: field_link_test[0]['url'] ?> – TechRemarker Jun 06 '11 at 21:24
  • Also in that views section the id for that field is "field_link_test_url" so I tried adding the "_url" but still nothing shows in the template. – TechRemarker Jun 06 '11 at 21:38