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

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

Related

Is there a bash function for determining number of variables from a read provided from end user

I am currently working on a small command line interface tool that someone not very familiar with bash could run from their computer. I have changed content for confidentiality, however functionality has remained the same.
The user would be given a prompt
the user would then respond with their answer(s)
From this, I would be given two bits of information:
1.their responses now as individual variables
2.the number of variables that I have now been given: this value is now a variable as well
my current script is as follows
echo List your favorite car manufacturers
read $car1 $car2 $car3 #end user can list as many as they wish
for n in {1..$numberofmanufacturers} #finding the number of
variables/manufactures is my second question
do
echo car$n
done
I am wanting to allow for the user to enter as many car manufacturers as they please (1=<n), however I need each manufacturer to be a different variable. I also need to be able to automate the count of the number of manufacturers and have that value be its own new variable.
Would I be better suited for having the end user create a .txt file in which they list (vertically) their manufactures, thus forcing me to use wc -l to determine the number of manufacturers?
I appreciate any help in advance.
As I said in the comment, whenever you want to use multiple dynamically created variables, you should check if there isn't a better data structure for your use case; and in almost all cases there will be. Here is the implementation using bash arrays. It prints out the contents of the input array in three different ways.
echo List your favorite car manufacturers
# read in an array, split on spaces
read -a cars
echo Looping over array values
for car in "${cars[#]}"
do
echo $car
done
echo Looping over array indices
for i in ${!cars[#]}
do
echo ${cars[$i]}
done
echo Looping from 0 to length-1
let numcars=${#cars[#]}
for i in $(seq 0 $((numcars-1)))
do
echo ${cars[$i]}
done

Cannot append to a file: Append replaces the content

The following command does not append but replaces the content
echo 0 >> /sys/block/nvme0n1/queue/nomerges
I don't want to replace but append. But I'm curious Is there something special about this file?
It also doesn't allow more than one character as its input.
Look at https://serverfault.com/questions/865787/what-does-the-nomerge-mean-in-linux-system
It might help you in understanding, that there are only 3 options that the file can take.
Also:
nomerges enables the user to disable the lookup logic involved with IO
merging requests in the block layer. By default (0) all merges are
enabled. When set to 1 only simple one-hit merges will be tried. When
set to 2 no merge algorithms will be tried (including one-hit or more
complex tree/hash lookups).

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.

Ubuntu 14.04 arbtt-stats index to large error

I've recently installed arbtt which seems to be an intersting, rule based, automatic time tracker. http://arbtt.nomeata.de/#what
I've got it working for the most part, but after 30 minutes or so of gathering stats, I end up with the following error.
Processing data [=>......................................................................................................................................................................................] 1%
arbtt-stats: Prelude.(!!): index too large
Does anyone have any suggestions on ways I can troubleshoot this issue, or better yet, solve it? I have 0 experience with the coding language used to create the rules (Haskell I believe). All I've done to this point is follow the documentation as closely as possible.
This error ultimately renders the tool useless since it doesn't gather data any longer than 30 minutes. To fix it, I have to delete the log and start from scratch. I'm primarily interested in the notion of having a customizable, rule based time tracker but I'm by no means tied to using arbtt.
Based on the comments below, I'm including some more information below.
When I try to run arbtt-recover I get a long list of errors that look like this. All of them seem to be related to an Unsupported TimeLogEntry.
Trying at position 1726098.
Failed to read value at position 1726098:
Unsupported TimeLogEntry version tag 0
As for the configuration file, here is what I have so far.
$idle > 30 ==> tag inactive,
-- A rule that matches on a list of strings
current window $program == ["Chrome", "Firefox"] ==> tag Web,
current window $program == ["skype"] ==> tag Skype,
current window $program == ["jetbrains-phpstorm"] ==> tag PhpStorm,
( current window $title =~ m!Inbox! ||
current window $title =~ m!Outlook! ) ==> tag Emails,
( current window $title =~ m!AdWords! ||
current window $title =~ m!Analytics! ) ==> tag Adwords,
It goes on further, but I'm fairly confident I've followed this same syntax for all other lines. The rest of the lines are following the same format but are project/client specific for me. If required, I'm happy to include the rest of the file.
As discussed in the comments: This is a case of a corrupt ~/.arbtt/capture.log. You can usually fix this by
running arbtt-recover
and then moving ~/.arbtt/capture.log.recovered to ~/.arbtt/capture.log.
The second manual step is required to avoid accidentially deleting too much data. You can test that the recovered file is better by making arbtt-stats using the recovered file by passing --logfile=~/.arbtt/capture.log.recovered to it.
Data corruption happens for example when there is an unclean shutdown, or other undetermined reasons. But the log file format is such that even after a corruption (e.g. a partial write of one sample), further samples will be written correctly and should be picked up by arbtt-recover, so you did not lose more than a few samples.

Resources