I'm trying to have my menus automatically change according to settings in my code so I don't have logic duplicated in my templates. Right now I use the route names to generate the urls with request.route_path(name) and determine what the current page the user is on with request.matched_route.name. My problem now is that I want to have different permissions on different views and automatically hide menu items that the user doesn't have permission to.
One of the major difficulties is that you can have multiple views for one route. But even if there's only one view associated with a route, I can't seem to find any simple way to retrieve it.
I'm using URL Dispatch. Is this something that'd only be do-able with traversal?
Normally I use a combination of the following patterns for this:
My views are organized into classed
The base class has a basic _menu which is a list of (menu_title, route_name, params) where params is an optionally present dict. When in the template I can use a menu property that builds the menu from the request and the above attribute.
In the template create a function that iterates over theses entries, shows each but checks with something like has_permission if the view is actually allowed.
These ideas should get you started on a dynamic solution. It works fine for me, but it might require some more tweaking, for example, I attach another value "active" to the generated menu based on the current route.
Related
I am building a liferay theme, which has two columns side by side. The right column is where the web contents will be displayed.
My implementation aims to build a menu (left column) that gets the titles from the web content titles and builds hierarchy (parent, child) based on a 'select' structure field that I added to each web content.
So far I was able to build this system using
Liferay.Service('/journalarticle/get-articles'...)
and some javascript coding.
Now the 'select' fields i use in my structure have predefined hard coded options.
How can i populate dynamically this option list so that whoever is managing content will automatically have all titles from all web contents available to choose a 'parent' from? So far a developer has to update this option list each time there is a new web content added.
#chadct : AFAIK Liferay not provide this default functionality, this is not good practice to populate dynamically value in structure field. But you wanted to achieve that functionality, then there are 4 solution :
Add one text field in structure which contains articleId of your parent web content.
You can add related article for that web content and write some sort of code to get article which consider as a parent of that web content.
Create Select DOM options form template which hold the list of article according to groupId and render on web content view mode, then you can select parent content from there and update content expando with articleId of parent webcontent. Remember this contains AJAX post request. and only show that control who is admin or loggedin user or depends on Role. Refer AJAX post calling
Hook edit_structure.jsp and add your logic here as you want.
Note : last one is worst but also a solution, Remember you need to modify your current solution.
Very simply I want to have multiple content regions on a single page. Note this is my first Modx site.
So far I have the home page and created child documents for the sub regions on the home page. All I want is to call them in the template.
For example there is a document with an id of 2, and I want the long title on the home page (id of 1).
Something like :
[[~2*longtitle]]
Unfortunately the above just returns the url to that sub document and not the longtitle of that document itself.
So far I've found no documentation on doing so. Does anyone know how to accomplish this?
You have 2 options, the hard way ~ the route you have chosen ;) and the easy way... which I will outline as well.
For what you are trying to do you are going to want to use either getResources http://rtfm.modx.com/display/ADDON/getResources which will allow you to loop over a collection of resources & extract the fields you need [in this case 'content'] or getresourceField http://rtfm.modx.com/display/ADDON/getResourceField which will allow you to specify a single resource & the field to extract, just call it multiple times in your template.
You might try:
[[getResources? &parents='[[*id]]' &tpl='myTpl' &includeContent='1']]
Should get all the child resources [up to default ~ 10] of the current resource, then you would create a template for get resources to loop over:
<h1>[[+longtitle]]</h1>
<p>[[+content]]</p>
notice the use of + instead of * for the resource fields
OR
the easy way, create template variables for your extra content areas, you can set them up as rich text areas as well. that way all your content for any given page is within the one resource ~ no need for you to create child resources to hold content for your header/footer/sidebar/etc
Either way will work, the TV method may use less overhead though.
you can use fastfield
[[#12.pagetitle]]
or in a call
[[#[[+id]].pagetitle]]
You can also grab all TVs of that resource, like
[[#12.myTv]]
see also: http://rtfm.modx.com/extras/revo/fastfield
How to implement Attribute to find his own name in the admin area in Opencart : Products - Attributes - Attributes? Is that there is a separate field and simply by driving into the field and displays the name of the attribute is an attribute, as usual searching for items in the admin by name, but only with attribute
It's hard to understand what you are asking, but if you are trying to use attributes for products then you must first define them at catalog>attributes>attributes.
To List attributes in the Products tab you will need edit these files
admin>view>template>catalog>product_form.tpl
admin>controller>catalog>product.php
If your understanding of PHP or Opencart isn't very strong it will help you to copy data from the attribute.php controller to the product.php controller.
As for the search function, this is something I haven't done before but you could try using the search function on the front of the website as reference.
I recommend working through this as best you can then asking more questions if or when you get stuck.
*Update
Ok so since HTML is your strenth it will be smartest to start from there. Open any of these files (the ones that have the data you need).
admin>view>template>catalog>attribute_form.tpl
admin>view>template>catalog>attribute_group_form.tpl
admin>view>template>catalog>attribute_group_list.tpl
admin>view>template>catalog>attribute_list.tpl
Then work backwards with what you see. The tpl will show variables that look like $attribute, track these back to
admin>controller>catalog>attribute.php
admin>controller>catalog>attribute_group.php
And you will see how all the code is used to pull the data from the model and format it if necessary.
One of the fields in my user profiles is a list of nodes. (This list is generated automatically, based on other data on the site.) Currently, it displays like this:
Nodes
nid1, nid2, nid3
I want it to look like this:
Nodes
$nid1->title, $nid2->title, $nid3->title
where each title is a link to its node. What is the best way to do this? I tried filling the field with links generated by l(), but the html gets filtered out.
Also, when using l(), is there a way to say: create a link to the node with $nid, no matter where it happens to be located at runtime?
Concerning the first question:
The field values of a profile list are run through ´check_plain()inprofile_view_field()`, so you can only get markup in there after they got loaded, which leaves you with at least two options, depending on where you want to alter the output:
Implement hook_user() and, on the 'view' operation, modify the field values in the $account->content array (Make sure that your modules weight is below that of the profile module or the values will not be in there yet).
Add your own preprocess functions for all templates where the fields are used and make your adjustments there. On first sight, these should be the following, but the list might be incomplete:
yourModule_preprocess_profile_block() (profile module)
yourModule_preprocess_profile_listing() (profile module)
yourModule_preprocess_user_profile_item() (user module)
As for the second question:
Also, when using l(), is there a way
to say: create a link to the node with
$nid, no matter where it happens to be
located at runtime?
I do not understand what you mean by "no matter where it happens to be located at runtime". Anything that is not covered by the following?
l('SomeTitle', 'node/' . $nid)
I am creating a gallery/albums site in Drupal 6.
Perhaps the description will be a bit detailed, but still on some reason it's a problem to create a gallery in Drupal in a simple way.
As for now I am using CCK + Views + FileField + ImageCache + Lightbox2 combination.
This has allowed me to
- create Album CCK node type that can hold multiple images
- create a view that displays Albums in 9x9 fashion (using pager and items per row)
But here is one problem. While the main 9x9 view with albums displays nicely, when I drill down into particular Album node by clicking it's picture, it displays the uploaded node images in a vertical row and I am unable to control it's formatting.
Apparently, I have 2 options
a) to somehow control the html output of my CCK field with its files (to divide into rows)
b) or to create another view to display pictures from one album
As for now, I am not sure which of these two ways is the best and what specifically I need to do.
a) I can create node-album.tpl file - but all its content will already be in a single $content variable, which I don't be able to break into 3 items in a row. Am I wrong?
b) if I decide to create a view to display items from a single Album node, I am not sure how I reference it from the parent Albums view. The problem is that in view's Fields section I am able to override the Link, but it offers only 2 replacement patterns to pass to a potential "child" view, which are [title] and [field_images_fid] - is that enough to create a child view to show images from a specific album?
I just recorded a screencast outlining one approach. There's quite a bit of discussion in the comment threads about alternative methods; I'd definitely suggest using Views Attach if you want more control over the presentation of the gallery itself.
I can create node-album.tpl file - but all its content will already be in a single $content variable, which I don't be able to break into 3 items in a row. Am I wrong?
You are right and wrong.
In your template.php file you can pass other variables into your node-album.tpl, you could pass in the $node variable and display in a very customised way, although this will remove flexibility later on, as if you use another module to add things to $content you will have to edit the tpl file to access new variables.
To do this you use the preprocess_page hook in the template.php file. You can add variables to the $vars array and use these in the node-album.tpl file. I think that $node will already be defined in the tpl file, which will probably make your life easier. you can disregard content altogether.
If this doesn’t work for you, you can also create a custom module and use hook_nodeapi and hook_theme to theme things any way you like, while still using $content. However this may be a bit too much work for you needs (if you want to go this way, reply and I'll write a separate answer).