IDX condition in a getresource tpl - modx

I use getresource like this:
[[!getResources? &tpl=`coffrets_id` &parents=`1115`]]
inside coffrets_id tpl I'd like to be able to do something like this:
[[+idx:is=`1`:then=`show only first getressrouce result`:else=``]]
[[+idx:is=`2`:then=`show only second getressrouce result`:else=``]]
[[+idx:is=`3`:then=`show only third getressrouce result`:else=``]]...
but I have no idea how to show only the result that matches the idx. Is there any solution?

Just use Templating Properties
[[!getResources?
&tpl=`coffrets_id`
&tpl_1=`coffrets_id_1`
&tpl_2=`coffrets_id_2`
&tpl_3=`coffrets_id_3`
&parents=`1115`
]]

Related

Logstash config, "if string contains..."

So, let's assume that I have a portion of a log line that looks something like this:
GET /restAPI/callMethod1/8675309
The GET matches a http method, and get's extracted, the remainder matches a URI, and also gets extracted. Now in the logstash config let's assume that I wanted to do something like this...
if [METHOD] == "GET" {
if [URI] (CONTAINS <--Is there a way to do this?) =="restAPI/callMethod1"{
....
Is there some way to do this? If so how would I go about doing that?
Thanks
You can achieve it simply by using the =~ (regexp) operator like this (see conditionals):
if [METHOD] == "GET" {
if [URI] =~ /restAPI\/callMethod1/ {
...

Jade conditional with select options

How to set the option (of select) to selected to match the current language of the page? Is there a way to inline it and simplify it something like this:
(value="en" #{Locale}==='en' ? ',selected="selected"': '')
I have tried some answers on this site, but they do not seem to work. Thank you.
This is the view:
if(#{Locale} ==='en')
option(value="en", selected="selected") #{English}
option(value="bg") #{Bulgarian}
else if(#{Locale} === 'bg')
option(value="en") #{English}
option(value="bg",selected="selected") #{Bulgarian}
Adapted from this answer, you could create a mix-in that handles the logic for you:
mixin lang-option(code, name)
if (Locale === code)
option(value=code, selected="selected")= name
else
option(value=code)= name
+lang-option('en', English)
+lang-option('bg', Bulgarian)
This solution works if you need to parameterize the 'disabled' attribute as well. Jade will not output attributes that evaluate to false.
//Selects the option when option.value == selectValue
mixin selectOption(option, selectValue)
option(value=option.value, disabled=option.disabled, selected=(option.value==selectValue))= option.label

How to write a compound IF statement checking two sets of two values

I know the title is confusing, but I can't figure our how to word it properly. I'm trying to figure out how to properly format a compound conditional in an IF statement in Excel. It's for a school project that's due tomorrow.
I already have something like this
=if(AND(b152="oval.jpg",c152="q'")OR(AND(b152="triangle.jpg", c153="p'")), "Correct", "Incorrect")
In psuedocode I want it to run something like this:
if (b152=="oval.jpg" && c152=="q'") or (b152=="triangle.jpg", c153="p'"):
print("YES!")
else
print("False!")
I know I'm missing something here. My current excel code returns false even if the conditions are true. Thanks ahead of time!
OR is a function in Excel, like AND. Try something like this:
=if(OR(AND(b152 = "oval.jpg", c152 = "q'"), AND(b152 = "triangle.jpg", c153 = "p'")), "Correct", "Incorrect")

Better way to ucfirst in a Jade template?

Is there a better way to capitalize the first character of a string in Jade than this?
for list in project.lists
- list.name = list.name.charAt(0).toUpperCase() + list.name.slice(1);
li #{list.name}
Doing this every time I want to capitalize a variable is ugly, is there any way in Jade that I can define a custom function that I have available in every template like:
for list in project.lists
li #{ucfirst(list.name)}
Thanks in advance!
The contents of #{} are executed as standard JS, so you can pass in helper functions for use with things like that. You haven't specified, but assuming you are using Jade along with Express, you can do something like this:
app.locals.ucfirst = function(value){
return value.charAt(0).toUpperCase() + value.slice(1);
};
That will expose a function called ucfirst within the Jade template. You could also pass it in as part of locals every time you render, but if you are using Express it will do it automatically.
If you're willing to resort to CSS, you can create a class that capitalizes the first letter of every word within the target element.
CSS
.caps {
text-transform: capitalize;
}
Jade
div.caps
each foo in ['one', 'two', 'three']
span #{foo}
Resulting HTML
<div class="caps"><span>one</span><span>two</span><span>three</span>
Resulting view
One Two Three
If you are using pug with gulp, this can be helpful:
mixin ucfirst(text)
- text = text.charAt(0).toUpperCase() + text.slice(1);
.
#{text}
Simply call this as any other mixin:
li
+ucfirst(list.name)

How does one add a conditional inside of a link in jade?

How does one add a conditional inside of a tag (link/anchor in my case) in jade?
Here's my pseudo code that of course won't work:
a(href="/foo", class="if (current_route[1] == 'foo'){active}") Go to Foo
How about
a(href="/foo", class=(current_route[1] === 'foo')? "active" : "") Go to Foo

Resources