I'm trying to output a template variable inside the if statement in ModX, but it gives no output.
I have multiple pages with links to articles and the point is to only output template variable content on the first page but not the others.
// This gives no output:
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=``]
// This outputs "yes" on the first page and "no" on others:
[[!#get.page:is=`1`:or:is=``:then=`yes`:else=`no`]]
I've even tried this, but it still does not give any output. I guess the problem is not about the output modifier:
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=`[[*content]]`]
I'm using ModX Revo 2.7.0
Any help is appreciated, thanks in advance!
Actually in your case missing a double closing angle bracket "]]"
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=``]]
The `or:is=` is matching against an empty state. Unless that is intentional you should be able to remove it. Also, the `:else=`` is the default state, so, you don't need that either.
The following should work and you'll have cleaner code:
[[!#get.page:is=`1`:then=`[[*content]]`]]
Related
Currently the code below will only show the HeroImage if one exists. If one doesn't exist, it doesn't show the other image blogImage. How can I change the code to show blogImage, if there is no HeroImage. Thanks
<img src="[[*HeroImage:isempty:then='[[*blogImage:phpthumbof=`w=1200&h=800`]] [[*]]':else='[[*HeroImage:phpthumbof=`w=1200&h=800`]] [[*]]']]" alt="[[*pagetitle]]" class="img-responsive"/>
Using the :default option should be enough:
[[*HeroImage:default=`[[*blogImage]]`:phpthumbof=`w=1200&h=800`]]
Ifempty and (default, empty, isempty) works like default value if input not specified else it returns the input value itself. So second else statement has no meaning and doesn't work.
For your purpose you can use "is" modifier like
[[*HeroImage:is=``:then=`[[*blogImage:phpthumbof=`w=1200&h=800`]]`:else=`[[*HeroImage:phpthumbof=`w=1200&h=800`]]`]]
And keep in mind using back-ticks for modx templating
I'd roll this a slightly different way, but it's likely the same result:
[[*HeroImage:neq=``:then=`[[*HeroImage:phpthumbof=`w=1200&h=800`]]`:else=`[[*blogImage:phpthumbof=`w=1200&h=800`]]`]]
When I make the "Read Cell" in "Excel application scope", I tried to output the read data from Excel by using "Write Line". However, It's not working and it ouput the error as in the Title. Could you someone make it up?
I had the same issue. I'm using the LookupDataTable activity. In my Excel file I have a mix of Strings and Integers. But somehow I also got the error:
NotSupportedException: StringConverter cannot convert from
System.Double.
I solved it by changing the variable from String to GenericValue.
I also tried to give it the Double type, but it didn't work because I think I have different types in the column.
Try this maybe be it will help you to check out
Convert.todouble
Lets say that there is a function in my Delphi app:
MsgBox
and there is a string which has MsgBox in it.
I know what most of you are going to say is that its possible, but I think it is possible because I opened the compiled exe(compiled using delphi XE2) using a Resource Editor, and that resource editor was built for Delphi. In that, I could see most of the code I wrote, as I wrote it. So since the variables names, function names etc aren't changed during compile, there should a way to execute the functions from a string, but how? Any help will be appreciated.
EDIT:
What I want to do is to create a simple interpreter/scripting engine. And this is how its supposed to work:
There are two files, scr.txt and arg.txt
scr.txt contains:
msg_show
0
arg.txt contains:
"Message"
And now let me explain what that 0 is:
First, scr.txt's first line is function name
second line tells that at which line its arguments are in the arg.txt, i.e 0 tells that "Message" is the argument for msg_show.
I hope my question is now clear.
I want to make a simple scripting engine.
In order to execute arbitrary code stored as text, you need a compiler or an interpreter. Either you need to write one yourself, or embed one that already exists. Realistically, the latter option is your best option. There are a number available but in my view it's hard to look past dwscript.
I think I've already solved my problem! The answer is in this question's first answer.
EDIT:
But with that, as for a workaround of the problem mentioned in first comment, I have a very easy solution.
You don't need to pass all the arguments/parameters to it. Just take my example:
You have two files, as mentioned in the question. Now you need to execute the files. It is as simple as that:
read the first line of scr.txt
check if it's a function. If not, skip the line
If yes, read the next line which tells the index where it's arguments are in arg.txt
pass on the index(an integer) to the "Call" function.
Now to the function which has to be executed, it should know how many arguments it needs. i.e 2
Lets say that the function is "Sum(a,b : integer)".It needs 2 arguments
Now let the function read the two arguments from arg.txt.
And its done!
I hope it will help you all.
And I can get some rep :)
I try to hide the getPage [[+pageNav]] Placeholder if there is no pagination. But I can't do the following.
[[!+pageNav:notempty=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]
Does someone know how I can hide the element with an apropriate output filter? (without own extra snippet). I also tried the following and some other (not likely to work variations).
[[!+pageNav:isnot=``:then=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]`
Are you calling that code in a chunk that is cached?
Otherwise i've experienced this aswell and it seems custom placeholders sometimes behave that way, it's probably due to the fact that they actually have some unprocessed value during the IF computation but when it's actually output you see nothing. Or that the value is somehow "null" instead of "" while modx output filter might do a strict comparison.
If you're not calling it in a cached chunk or part of code, i suggest first trying with another getPage placeholder such as pageCount or total.
Like:
[[!+pageCount:gt=`1`:then=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
If that still doesn't work, a last resort in the form of a simple snippet will always solve it, like:
[[!outputPagination? &total=`[[+total]]` &limit=`XX` &output=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
In snippet:
if ($total > $limit) {
return $output;
}
Shouldn't it be...
[[!+page.nav:notempty=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
Well, there is a much more easier way to do it than in the first answer. It's like TheMistaC says, even if my answer is a lot easier:
[[!+page.nav:notempty=`
[[!+page.nav]]
`]]
I use it to display a list of articles with getResources, so I know this works fine.
I am using a simple looping plugin so that my template looks like this:
{exp:loop_plus start="1" end="4" increment="1"}
<h3>{slide_{index}_title}</h3>
{/exp:loop_plus}
However, I am ending up with the following output:
<h3>{slide_1_title}</h3>
<h3>{slide_2_title}</h3>
<h3>{slide_3_title}</h3>
<h3>{slide_4_title}</h3>
Is there any way I can have dynamic variable names like this? I am not looking for alternative methods for building a slider, I simply would like to know if the dynamic variable names like this is possible. Thanks!
I'm assuming that Loop Plus (http://devot-ee.com/add-ons/loop-plus) sets the {index} part, so the question is what is defining {slide_1_title}...?
Assuming you have an entry field or variable with this defined, what you have is correct, but if it's not working, it means there's a parsing order issue.
Let's assume the code you supplied is wrapped in a {exp:channel:entries} tag pair, what happens is EE will try to parse the variable first, so will see: {slide_{index}_title} which doesn't exist. The {exp:loop_plus} add-on will then parse it, converting it to {slide_1_title} (but to late as channel:entries has already tried to parse it), which is what is finally output to the template.
So what you want to ensure is that EE parses {exp:loop_plus} before {exp:channel:entries}, do this using parse="inward" tag:
{exp:loop_plus start="1" end="4" increment="1" parse="inward"}
<h3>{slide_{index}_title}</h3>
{/exp:loop_plus}
This is a global EE parameter that EE uses to control parse order - you won't find it documented under the specific add-on. By adding the parameter, it means this child tag will get parsed before it's parent.
One way you could do it is to declare a preload_replace variable in your template and use it in your custom field name.
So something like:
{preload_replace:my_var_prefix="whatever"}
And then in your loop, you could then use:
{slide_{my_var_prefix}_title}