How do you embed the tags block into a template?
Permalink
Hi There,
I have a site that requires separate tags for news and for projects.
If I change the attribute handle for the built-in tags block, how can I then embed the block so I can change the attribute handle?
I'm testing the embed code by leaving the tags handle as 'tags' for now.
With the following code, I can show the tags assigned to the current page but can't display all tags
I then have a custom block template called project_tags.php
But I would like to show a list of all the tags - not just the ones assigned to the current page - is that possible?
Hope this all makes sense.
Cheers
Ben
I have a site that requires separate tags for news and for projects.
If I change the attribute handle for the built-in tags block, how can I then embed the block so I can change the attribute handle?
I'm testing the embed code by leaving the tags handle as 'tags' for now.
With the following code, I can show the tags assigned to the current page but can't display all tags
<?php $tags = BlockType::getByHandle('tags'); $targetPage = Page::getByPath('/projects/project-search-results'); // $targetPage needs to be a valid page object, or links will not appear $tags->controller->targetCID = $targetPage->getCollectionID(); $tags->render('templates/project_tags'); ?>
I then have a custom block template called project_tags.php
But I would like to show a list of all the tags - not just the ones assigned to the current page - is that possible?
Hope this all makes sense.
Cheers
Ben
Could there be something in the render template limiting the tags to only those assigned to the current page maybe?
So I was missing ->controller on displayMode and cloudCount - final embed code is:
<?php // here's an example using a different attribute handle $tagsBT = BlockType::getByHandle('tags'); // get an instence of the tags block and name it $tagsBT $tagsBT->controller->attributeHandle = "another_tag"; // attribute handle of the tags to display $targetPage = Page::getByPath('/projects/project-search-results'); // when you click a tag, this is the page that displays the results - must contain a search block and must be a valid page or no tags will display $tagsBT->controller->targetCID = $targetPage->getCollectionID(); // links tags to the $targetPage above $tagsBT->controller->displayMode = 'cloud'; // possible modes: cloud = displays all tags / page = displays tags assigned to the current page only $tagsBT->controller->cloudCount = '10'; // number of tags to display when using cloud displayMode above $tagsBT->render('view'); // display template used to control how the tags render ?>
But I still can't get it to display all the tags (I'm sure cloudMode is supposed to display all the tags) - but it only outputs the tags assigned to the current page.
I also guessed at what each item does in the comments so hope they're right!