How to display resources in modx with a specific TV - modx

I'm trying to use getResources to only show the resources with a certain type of template variable. I know I'm doing something wrong b/c the page is displaying all template vars:
[[!getResources?
&parent=`[[*id]]`
&showHidden=`1`
&limit=`0`
&tpl=`Dining Section`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&tvPrefix=``
&tvFilters=`Dining Section Title != ''`]]
In the last argument I am trying to only display resources with the TV "Dining Section Title". Any help would be appreciated.

Your syntax is missing the backticks around the option values and you cannot have spaces in Chunk or TV names. Check what the actual TV and Chunk names are, then reformat your snippet call like this:
[[!getResources?
&parent=`[[*id]]`
&showHidden=`1`
&limit=`0`
&tpl=`DiningSection`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&tvPrefix=``
&tvFilters=`DiningSectionTitle!=''`
]]

I solved it. I needed to remove the single quotes from the tvFilters value.
[[!getResources?
&parent=`[[*id]]`
&showHidden=`1`
&limit=`0`
&tpl=`Dining Section`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&tvPrefix=``
&tvFilters=`Dining Section Title!=`
]]
Thanks okyanet for the help.

Related

MODX getResources displays child resources of unlisted resource

I have the following getResources code on a page:
[[!getResources?
&resources=`57,77`
&depth=`1`
&tpl=`customersListTPL`
&limit=`99`
&sortdir=`ASC`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&showHidden=`1`
&depth=`0`
&sortby=`menuindex`
]]
I want it to only display data from the resources 57 and 77, but it is also displaying child resources from the resource this is on too.
Anyway I can stop that?
For some design-reason getResources will allways mix results from the defined parents (explicit or implicit) if the &parents config is not set.
If you only want to use the defined &resources you have to explicitly disable the parents by using:
&parents=`-1`
For reference: That's not the only oddity of getResources, the limit is preset to 5 and the sort order is createdon=DESC (for example).
Manual: https://rtfm.modx.com/extras/revo/getresources#getResources-Examples

modx revo getresources multiple templates

Is it possible to use multiple tpl's in the getResources call?
This is my code so far:
[[!getPage?
&element=`getResources`
&tpl=`overzichtTpl`
&parents=`2, 74`
&hideContainers=`0`
&showHidden=`1`
&limit=`50`
&sortby=`RAND()`
&depth=`0`
&includeTVs=`1`
]]
What I want to achieve is the folowing: the resource call
&parent=`2`
has to use
&tpl=`overzichtTpl`
and the
&parent=`74`
has to use
&tpl=`overzichtAdvTpl`
Furthermore I want to have the output from both calls displayed at random. (otherwise I only have to use 2 seperate getResources calls). For example like this:
resource-call
If you have the solution, I'm looking forward to hear from you.
This is clearly documented using tpl_N & tplnN:
https://rtfm.modx.com/extras/revo/getresources
If you need to randomize your templates, write a snippet and execute it from the getResources call (i.e. &tpl=`RandomizeChunkName`) You don't need an extra wrapper chunk.

ModX getResources - Chunks in the tpl are displaying parent's content

I have this getResourcesCall
[[!getResources? &tpl=GRTpl&includeContent=1&includeTVs=1&parents=[[*id]]]]
In GRTpl I am including [[+content]] tags, but they only display the parent's content, not the content of the children. What gives!?
UPDATE:
I am using ModX output filters in GRTpl. So I have a Single-Select Listbox that displays chunks based on the selection. Here is GRTpl:
[[+tv.section_type:eq=`Type One`:then=`[[$Type One Chunk]]` ]]
[[+tv.section_type:eq=`Type Two`:then=`[[$Type Two Chunk]]` ]]
[[+tv.section_type:eq=`Type Three`:then=`[[$Type Three Chunk]]` ]]
[[+tv.section_type:eq=`Type Four`:then=`[[$Type Four Chunk]]` ]]
So I found the solution. In GRTpl I'm passing a var into each chunk:
[[+tv.section_type:eq=`Type One`:then=`[[$Type One Chunk? &content=`[[+content]]` ]]` ]]
[[+tv.section_type:eq=`Type Two`:then=`[[$Type Two Chunk? &content=`[[+content]]` ]]` ]]
[[+tv.section_type:eq=`Type Three`:then=`[[$Type Three Chunk? &content=`[[+content]]` ]]` ]]
[[+tv.section_type:eq=`Type Four`:then=`[[$Type Four Chunk? &content=`[[+content]]` ]]` ]]`
Then in the chunks [[+content]] displays the child resource's content.
The method used above will result in a lot of extra processing and a slower web site.
Two options:
1) Read Jason Coward's excellent article on Conditionals.
The basic problem is the code shown above will get expanded and processed by MODX even if it does not meet the conditional.
So instead of:
[[*field:is=0:then=[[!SomeScript]]:else=[[$SomeChunk]]]]
Use:
[[[[*field:is=0:then=!SomeScript:else=$SomeChunk]]]]
See http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/ for the details.
2) For further enhancements, replace getResources with pdoResources and use its excellent Conditional Templates which means you do not need to use Conditionals at all.
With pdoResources you can do the following:
[[!pdoResources? &includeTVs=section_type &tplCondition=section_type
&conditionalTpls=`{"Type One":"Type One Chunk","Type Two":"Type Two Chunk"}
and so on.
Google "modx pdotools" for the docs.
Using this method I sped up what was a TV laden getResources call about 8 times faster.
See http://forums.modx.com/thread/90995/performance-question-with-getresources

Using getResources and a custom date TV, how can I limit my results by the year entered in my TV?

In MODx Revolution, while using getResources and a custom date TV (called: press-release-date), how can I limit my results by year (using a URL param to set the year, so I could enter any year)?
For example, my URL has page.html?year=2012
I want my results from getResources to only include ones associated with that year. I believe I want to use the &where property (if so, I am certainly botching the formatting):
&where=`{"press-release-date":[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
I've also tried
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
Thanks!
UPDATE:
This is the full code I am using currently:
[[!getResources?
&parents=`780,781,782,783,784`
&tpl=`list-press-tpl`
&limit=`1000`
&sortdir=`DESC`
&includeTVs=`1`
&includeContent=`1`
&depth=`0`
&showHidden=`1`
&sortbyTV=`press-release-date`
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
]]
You are going to want to use the &tvFilters attribute: http://rtfm.modx.com/display/ADDON/getResources you will probably have to also &includeTVs, &includeTvsList and ~possibly~ also &processTVList. As to how to strip the post value from the url, you may have to write a quick little snippet that grabs all your url variables & sets them as placeholders. something along the lines of:
foreach($_POST as $key => $value){
$modx->setPlaceholder($key,$value);
}
Then you should be able to access them:
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`[[+year]]`]}`
at a guess... not tested.:)
You can try tvFilters instead. But you will have to translate your [[+year]] into your press-release-date date format and limit search inside intertleave:
&tvFilters=`press-release-date>=[[+year:dec:strtotime]]||press-release-date<=[[+year:strtotime]]`
http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
http://rtfm.modx.com/display/revolution20/Date+Formats
http://ru2.php.net/strtotime

Help using ExpressionEngine template tags and conditionals

I've taken on this EE2 project and I don't have much experience with it.
I've installed two plugins, SessionVariables and Freebies, to fetch a url segment and act according to its value.
So, basically:
{if "{exp:freebie:any name="es"}" == "true"}
Hola Mundo!
{exp:session_variables:set name="current_language" value="_es"}
{if:else}
{exp:session_variables:delete name="current_language"}
Hello World!
{/if}
The strange thing is that whan I go to site.com/es/hello it prints "Hola Mundo" but it actually calls both function set() and delete() of session_Variable's plugin.
I'ts driving me crazy, I'd appreciate any help you can provide.
http://www.putyourlightson.net/projects/session_variables
https://github.com/averyvery/Freebie
When using advanced conditionals in EE, all tags within those conitionlas are parsed regardless, as advanced conditionals are parsed later than most other tags in the parse order. This is why the session_variables tag is being called within both conditions in your example (even though only the first bit of content is displayed by the template parser).
The fix is to use "simple conditionals", which are parsed much earlier:
{if "{exp:freebie:any name="es"}" == "true"}
Hola Mundo!
{exp:session_variables:set name="current_language" value="_es"}
{/if}
{if "{exp:freebie:any name="es"}" == "false"}
{exp:session_variables:delete name="current_language"}
Hello World!
{/if}
Since this came up pretty early on a Google search I figure I'd mention the add-on IfElse. It'll return the proper condition, the ones that fail (return false) are stripped out. Ergo only the desired condition is run.
As Derek said knowledge of the parse order is vital, in this case both calls to {exp:session_variables:...} are being run regardless of the validity of the conditions. However, with IfElse your code would run as desired while avoiding advanced conditionals so not only do you execute what you want it does it much earlier in the parse order to boot.
E.g.
{exp:ifelse parse="inward"}
{if "{exp:freebie:any name="es"}" == "true"}
Hola Mundo!
{exp:session_variables:set name="current_language" value="_es"}
{if:else}
{exp:session_variables:delete name="current_language"}
Hello World!
{/if}
{/exp:ifelse}
When "{exp:freebie:any name="es"}" == "true" then {exp:session_variables:set name="current_language" value="_es"} will run and not {exp:session_variables:delete...}. As if your code read:
Hola Mundo!
{exp:session_variables:set name="current_language" value="_es"}
Also, again, this will happen at the parse order of {exp:ifelse...}, not after advanced conditionals.
The one caveat to note is that you cannot nest {exp:ifelse...}.
There are probably other add-ons like IfElse (check out Switchee by the same author) for the same or similar contexts, but this is what I know and use.

Resources