What is the right way to get a current topic?
Permalink 3 users found helpful
The Page List filtering is great, but it is also the weakness of concrete5.
If a user click a link of topic tree, we should show which topic node is current, but we can't now.
So, I'd like to get the topic of current url once, then pass it to the several elements, like a title tag (header_required element), Page Title block, Breadcrumb Nav (Auto-Nav).
Any suggestions?
If a user click a link of topic tree, we should show which topic node is current, but we can't now.
So, I'd like to get the topic of current url once, then pass it to the several elements, like a title tag (header_required element), Page Title block, Breadcrumb Nav (Auto-Nav).
Any suggestions?
Thank you for your advice! I've made a branch of this feature.
https://github.com/hissy/concrete5-5.7.0/commit/d59dc0c8d93feb7f27a4...
I'd like to send pull request of this. How do you think?
I think this reactive page title avoids duplicate title tag problem.
http://blog.raventools.com/the-most-common-seo-mistakes/...
https://github.com/hissy/concrete5-5.7.0/commit/d59dc0c8d93feb7f27a4...
I'd like to send pull request of this. How do you think?
I think this reactive page title avoids duplicate title tag problem.
http://blog.raventools.com/the-most-common-seo-mistakes/...
The modification to the page title block looks great. I think we'd approve that quickly.
The header_required.php snippet looks a little bit more brittle, though. I'm sure it works, but we don't usually like database calls directly in elements, and there's got to be a better way to change the title through a block action than just hard coding a single call like this. I definitely think there's a reason to want to do this, though. Maybe I can add a github issue for some functionality for this, and we could get it into 5.7.4, while we modify the page title block in time for 5.7.3.2.
The header_required.php snippet looks a little bit more brittle, though. I'm sure it works, but we don't usually like database calls directly in elements, and there's got to be a better way to change the title through a block action than just hard coding a single call like this. I definitely think there's a reason to want to do this, though. Maybe I can add a github issue for some functionality for this, and we could get it into 5.7.4, while we modify the page title block in time for 5.7.3.2.
Thanks for the review. I'll create a pull request including a modification for page title only.
I realize the topics documentation is on the roadmap however, Is there a method to get/display the current topic from the page object?
Like in a custom page-list template...
Like in a custom page-list template...
I'd love to hear the answer, too.
I can't figure out how to display the current topic in a portfolio project page.
I can't figure out how to display the current topic in a portfolio project page.
If you just want to display the current topic of a page, do this from within your page or block template
$c = Page::getCurrentPage();
print $c->getAttribute('my_topic_handle', 'display');
where "my_topic_handle" is the handle of the topic attribute for the page. (e.g. "blog_entry_topics."). This will get a text string of selected topic names.
If you want to do more with topics, you can do
$topics = $c->getAttribute('my_topic_handle');
which will give you an array of \Concrete\Core\Tree\Node\Type\Topic objects that corresponds to any selected topics. You can loop through these, get their numerical IDs to use for searching, etc...
$c = Page::getCurrentPage();
print $c->getAttribute('my_topic_handle', 'display');
where "my_topic_handle" is the handle of the topic attribute for the page. (e.g. "blog_entry_topics."). This will get a text string of selected topic names.
If you want to do more with topics, you can do
$topics = $c->getAttribute('my_topic_handle');
which will give you an array of \Concrete\Core\Tree\Node\Type\Topic objects that corresponds to any selected topics. You can loop through these, get their numerical IDs to use for searching, etc...
Thank you andrew, but I don't get the text string of the current topic within a block template.
print $c->getAttribute('project_topics', 'display'); gives me "Array" as a text string.
var_dump($c->getAttribute('project_topics', 'display')); shows an array.
var_dump($c->getAttribute('project_topics')); shows almost the same array except for a different number behind the #.
Here my output from var_dump($c->getAttribute('project_topics', 'display'));
If I understand you right, in my case print $c->getAttribute('project_topics', 'display'); should print "Activities" instead of "Array". Does anyone have an idea what I'm doing wrong? Or does anyone have an idea how I can help myself, except for waiting for the documentation about topics?
Thank you very much.
print $c->getAttribute('project_topics', 'display'); gives me "Array" as a text string.
var_dump($c->getAttribute('project_topics', 'display')); shows an array.
var_dump($c->getAttribute('project_topics')); shows almost the same array except for a different number behind the #.
Here my output from var_dump($c->getAttribute('project_topics', 'display'));
array(1) { [0]=> object(Concrete\Core\Tree\Node\Type\Topic)#3839 (12) { ["childNodes":protected]=> array(0) { } ["childNodesLoaded":protected]=> bool(false) ["treeNodeIsSelected":protected]=> bool(false) ["error"]=> string(0) "" ["treeNodeID"]=> string(2) "18" ["treeNodeTypeID"]=>
Viewing 15 lines of 30 lines. View entire code block.
If I understand you right, in my case print $c->getAttribute('project_topics', 'display'); should print "Activities" instead of "Array". Does anyone have an idea what I'm doing wrong? Or does anyone have an idea how I can help myself, except for waiting for the documentation about topics?
Thank you very much.
Okay I see that the problem is the attribute value loads an array of the Topic objects rather than a text list. Which is good really because now you can output them however you want. You just have to use the method to retrieve the name.
See this API page to see what methods are available for these objectshttp://concrete5.org/api/class-Concrete.Core.Tree.Node.Type.Topic.h... Hint for anybody finding if you var_dump( $object ) whatever the namespace of the object is (in this case Concrete\Core\Tree\Node\Type\Topic) just put that in Google and the API page will show up as first result.
Test with this first which later we'll use in a loop:
Now presuming you want to list all the topics, with some markup here is a loop:
See this API page to see what methods are available for these objectshttp://concrete5.org/api/class-Concrete.Core.Tree.Node.Type.Topic.h... Hint for anybody finding if you var_dump( $object ) whatever the namespace of the object is (in this case Concrete\Core\Tree\Node\Type\Topic) just put that in Google and the API page will show up as first result.
Test with this first which later we'll use in a loop:
$topics = $c->getAttribute('project_topics', 'display'); print $topics[0]->getTreeNodeDisplayName(); // print display name for first topic
Now presuming you want to list all the topics, with some markup here is a loop:
Thank you so much goldhat!
Your code helps me a lot. I was able get get the current topics by array_map and implode $c->getAttribute('project_topics'), but I was sure that's not the right way. I know the API pages but I wasn't abled to connect things right.
With your example things start to make sense to me. Thank you for that. :)
I'm still confused why the attribute value loads an array of objects, when the parameter 'display' is given. I've searched the API pages and the code to take a look at getAttribute(), but I just don't get it. Maybe taking some time and some deeper thoughts will help.
Your code helps me a lot. I was able get get the current topics by array_map and implode $c->getAttribute('project_topics'), but I was sure that's not the right way. I know the API pages but I wasn't abled to connect things right.
With your example things start to make sense to me. Thank you for that. :)
I'm still confused why the attribute value loads an array of objects, when the parameter 'display' is given. I've searched the API pages and the code to take a look at getAttribute(), but I just don't get it. Maybe taking some time and some deeper thoughts will help.
Bump! Karma points a takin...
Anyone?
Anyone?
It's more complicated in header_required and would probably require some reworking, it'd be good to think about how this might work.