Can I use placeholders inside MODX Revolution FormIt parameters? - modx

I try to learn MODX FormIt component usage (MODX revolution v.2.7.0, FormIt v. 4.1.1). Now I try to set validation rules for form field, such as "required, only numbers, greater than", meanwhile I want to use placeholder for minimal value. I call FormIt like this:
[[!FormIt?
&hooks=`openSession`
&redirectTo=`1`
&placeholderPrefix=``
&validate=`my_field:required:isNumber:minValue=`[[!+my_min_value]]``
]]
but I can input any number in 'my_field' field. If I use number for minValue instead of placeholder, all works fine. Placeholder is successfully resolving into number in the form below, too.
When I am wrong?

IIRC, you cannot use placeholders in the parameters.
Although, you should try with the following code, in case it is now supported in latest versions:
[[!FormIt?
&hooks=`openSession`
&redirectTo=`1`
&placeholderPrefix=``
&validate=`my_field:required:isNumber:minValue=^[[!+my_min_value]]^`
]]
OR
You could use custom validator, in which you should be able to use getPlaceholder to read your placeholder.
For more details on why use ^ instead of back-ticks, please see https://docs.modx.com/extras/revo/formit/formit.validators

Related

Dialogflow: if condition based on time response

I am making a pizza delivery chatbot and one of the training samples is
Are you open right now?
PARAMETER NAME ENTITY RESOLVED VALUE
time #sys.time now
One of the responses I want to have is if the time is between 12 am and 6 am , the reponse I coded is :
{{#if $time> 12:00:00}}I think it is too late{/if}}
But the response i am getting is :
{#if 12:00:34> 12:10:00}I think it is too late{/if}, which is wrong. Can someone help me on how to resolve this.
TIA
The Response section has a very very simple templating system - it allows for parameter/value replacement, and that is about it.
So you can specify a parameter value from an input phrase using something like $parameter-name, while parameter values in a Context or Event would be #context-name.parmaeter-name. You don't need the {braces} to do the evaluation, since those are used to escape the $ and # as special characters. So if you needed to show "$100", you would write that as ${100}. If you need the braces to be displayed, you'd include those inside another set of braces, which is why your text seems to get the braces removed.
You will need to put this processing in your fulfillment code. Libraries such as multivocal will let you create responses and setup response logic using templates. (Multivocal uses the handlebars templating library, for example.)

Calling a template variable from an output modifier in Modx?

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]]`]]

Modx ifempty then else statements

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`]]`]]

modx - getPage - [[+pageNav]] Placeholder always has a value

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.

expression engine dynamic variable names: {slide_{index}_title}

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}

Resources