Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Tagfield - Get link to page

Go to End


Nobrainer Web

Community Member, 138 Posts

3 October 2010 at 10:08am


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'
$fields->addFieldToTab('Root.Content.Tags', new TagField('RelationTags', null, null, 'Page'));

Tag.php is:
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 %>
<% end_if %>
<% end_control %>