Calling Custom Attributes from Application into Packaged Theme
Permalink
Hi, I hope someone could help guide me in the right direction.
I have just begun to dig into Concrete5 8.(whatever the version).... and have been tasked with creating a page template that dynamically displays a side bar iterating lists of pages, files and posts. Bit like WordPress basing the feeds on categories and tags.
So my programming thinking is as follows:
- tag everything for the task with the same tag e.g. (news)
- use my newly created custom attribute 'category' to place the individual content pieces into news categories
- use a php switch case to feed certain categories when a certain category ID is assigned to the page itself.
So: if page category is 1, then feed category 3, if page category is 3, feed 2 and so on.....
I have successfully created the attributes and they are working well, but outside of the theme (which is in a package). I have declared the name spaces of the new attribute files in the theme's controller and have tried a couple of methods (in terms of public functions) but the category assigned to the page won't print or echo out as a starter point to getting the switch case in place.
I appreciate that the above is a call for help, and do not in any way want someone writing any code for me on this. I have scoured the web for some resource, but can't seem to find anything that has helped. Any nudges in the right direction to a document or tutorial would be greatly appreciated. Many thanks in advance.
I have just begun to dig into Concrete5 8.(whatever the version).... and have been tasked with creating a page template that dynamically displays a side bar iterating lists of pages, files and posts. Bit like WordPress basing the feeds on categories and tags.
So my programming thinking is as follows:
- tag everything for the task with the same tag e.g. (news)
- use my newly created custom attribute 'category' to place the individual content pieces into news categories
- use a php switch case to feed certain categories when a certain category ID is assigned to the page itself.
So: if page category is 1, then feed category 3, if page category is 3, feed 2 and so on.....
I have successfully created the attributes and they are working well, but outside of the theme (which is in a package). I have declared the name spaces of the new attribute files in the theme's controller and have tried a couple of methods (in terms of public functions) but the category assigned to the page won't print or echo out as a starter point to getting the switch case in place.
I appreciate that the above is a call for help, and do not in any way want someone writing any code for me on this. I have scoured the web for some resource, but can't seem to find anything that has helped. Any nudges in the right direction to a document or tutorial would be greatly appreciated. Many thanks in advance.
Hi Mr Dilkington,
yes of course, thanks for the reply. So, I come from a front-end background predominantly with AngularJS, a MVC Framework also. I have attached the file structure I am currently working with and from research, the previous developer has created a packaged theme where I require "injecting" my new custom attributes into the packaged theme. so open files need to be injected into the package directory.
I have built the attribute (a select attribute) using this documentation:
https://documentation.concrete5.org/developers/attributes/creating-c...
I tried the attributes into themes, but the results weren't good - had to retrace my steps. I guess what I am needing to understand is the equivalent process of "dependency injection" in Concrete5 - where I am able to see that external features are able to be injected into a controller and then exposed to the views.
I have a page template which requires exposure to this select custom attribute. I can then implement a pHp switch case, where when a certain category is assigned to the page template, it only shows a certain category of content in the right hand side bar - which will be an iteration in list format.
I've tried mapping the attribute in the Application directory to the theme package and then declared a new public function building off the attribute, but I am getting lots of "call to member function .......() undefined". So in AngularJS terms, the new feature isn't binding to the view, so I can play with the data. I'm sure there are better pHp terms to use here. if I've missed any details out, please let me know and I will clarify further.
yes of course, thanks for the reply. So, I come from a front-end background predominantly with AngularJS, a MVC Framework also. I have attached the file structure I am currently working with and from research, the previous developer has created a packaged theme where I require "injecting" my new custom attributes into the packaged theme. so open files need to be injected into the package directory.
I have built the attribute (a select attribute) using this documentation:
https://documentation.concrete5.org/developers/attributes/creating-c...
I tried the attributes into themes, but the results weren't good - had to retrace my steps. I guess what I am needing to understand is the equivalent process of "dependency injection" in Concrete5 - where I am able to see that external features are able to be injected into a controller and then exposed to the views.
I have a page template which requires exposure to this select custom attribute. I can then implement a pHp switch case, where when a certain category is assigned to the page template, it only shows a certain category of content in the right hand side bar - which will be an iteration in list format.
I've tried mapping the attribute in the Application directory to the theme package and then declared a new public function building off the attribute, but I am getting lots of "call to member function .......() undefined". So in AngularJS terms, the new feature isn't binding to the view, so I can play with the data. I'm sure there are better pHp terms to use here. if I've missed any details out, please let me know and I will clarify further.
A quick update, I decided to follow the next chapter again and with a better understanding of name spaces, I have managed to install the attribute as a package.
I need to associate this new feature to the page types within the theme, but struggling with the final instruction:
"so let's add this code for associating this attribute type to the page attribute category".
any guidance as to how this can be actioned, would be appreciated. TIA.
I need to associate this new feature to the page types within the theme, but struggling with the final instruction:
"so let's add this code for associating this attribute type to the page attribute category".
$service = $this->app->make('Concrete\Core\Attribute\Category\CategoryService'); $category = $service->getByHandle('category_type')->getController(); $category->associateAttributeKeyType($type);
any guidance as to how this can be actioned, would be appreciated. TIA.
You'll no doubt find thishttp://webli.us/cheatsheet/doku.php... helpful
Hi Sir!
thanks for this, I found this yesterday. Sadly, I think my problem might be a little more complicated - could be wrong though. My attribute is stored in Application and I am trying to get it to expose to pages in a packaged theme.
thanks for this, I found this yesterday. Sadly, I think my problem might be a little more complicated - could be wrong though. My attribute is stored in Application and I am trying to get it to expose to pages in a packaged theme.
Can you include more specific details about what you are trying to create, please. This will help in seeing if there is a built-in approach to accomplish the task.