Jump to:

22997 Posts in 11844 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Tagfield - Get link to page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1048 Views
  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Tagfield - Get link to page Link to this post

    Hello,

    I have a tagfield on my pages, where content editors can tag pages with words and sentences that is relevant to the content on a page.
    I need to print out each Tag of child pages as a <li> and add a link to the tag, that on click will take the visitor to the page that holds the tag.

    The below code lets me add tags to pages and also prints them to html, but i dont know how to add the link for the related page - please help.

    In my Page.php i have:
       static $many_many = array(
          'RelationTags' => 'Tag'
       );
    and
       $fields->addFieldToTab('Root.Content.Tags', new TagField('RelationTags', null, null, 'Page'));

    Tag.php is:
    <?php
       class Tag extends DataObject {
          static $db = array(
             'Title' => 'Varchar(200)',
          );

          static $belongs_many_many = array(
             'Pages' => 'Page'
          );
       }
    ?>

    In template
    <% control Children %>
          <% if RelationTags %>
             <ul id="tags">
             <% control RelationTags %>
                <li><a href="$Link">$Title</a></li>
             <% end_control %>
             </ul>
          <% end_if %>
       <% end_control %>

    1048 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.