Back to Genesis and Procedures. Problem assigning variables

Hello everyone.

I thought I understood the problems I was having last week with the code due to variables inside \procedures, and I’ve managed to make functional modifications to it.
But with the following code, I don’t know what’s really happening. It doesn’t apply the values ​​in $values, and I’m not sure why. If I replace the values ​​with the ones I want, it works, so I think something’s wrong there.
Example: $values=" 'danger' 'callout-lateral' "

\procedure callout(type:"note", src, title, model, status, width:"100%", class)
<$let theme-class   = {{{ [[$:/palette]get[text]get[color-scheme]else[light]addprefix[theme-]] }}} 
      callout-title = {{{ [<title>!is[blank]] :else[<type>titlecase[]]  }}}
      callout-model = {{{ [<model>!is[blank]addprefix[-]else[ ]] [<class>] +[join[ ]] }}}
      icon-tiddler  = {{{ [all[tiddlers+shadows]tag[$:/tags/TimitAdmonitions/Image]contains:callout-type<type>]
                        :else$:/plugins/timit/admonitions/images/note }}}
      source        = {{{ [<src>get[text]else<src>] }}} >
<div class=<<theme-class>> style=`width:$(width)$;`>
<$genesis $type="details" 
$names={{{ data-callout class [<status>match[open]then[open]] +[join[ ]] }}} 
$values="$(type)$ 'callout'$(callout-model)$" >
<summary class="callout-title">
<div class="callout-icon"><$transclude tiddler=<<icon-tiddler>> field=text/></div>
<div class="callout-title-inner"><<callout-title>></div>
<div class="callout-fold">{{$:/plugins/timit/admonitions/images/chevron}}</div>
</summary>
<div class="callout-content">
<$transclude tiddler=<<source>> field=title mode=block />
</div>
</$genesis>
</div>
</$let>
\end callout

I’ve thought about it a lot, but nothing. Thanks to @Scott_Sauyet in this post Problem with passing the value of the "status" variable in a procedure with a "details" element - #8 by Scott_Sauyet, I now have an alternative to do the same thing, but I’d like to understand what I’m doing wrong in this piece of code.

I use this code for call th procedure: <<callout type:"bug" model:"lateralb" title:"" status:"open" src:"Mi texto" class:"Pepe" width:"70%">>

Thank you very much.

1 Like

To use substituted attribute values (the $(var)$ syntax), you need backticks instead of quotes:

$values=`$(type)$ 'callout'$(callout-model)$` 

-e

Hi Eric.

Thanks for the tip. I hadn’t thought of that. :man_facepalming:

Would it be possible to specify variables in this or a similar way, or is the one you posted earlier the only one: $values=`<type> 'callout'<callout-model>` >

I’ve run several tests and haven’t found any that worked.

Thanks.

1 Like

If you want to avoid the backtick syntax, you can use the older “filtered transclusion” technique to contruct the $values attribute, like this:

$values={{{ [<type>] [[ 'callout']] [<callout-model>] +[join[]] }}}

-e

2 Likes

The $(var)$ syntax is the only way to substitute the value of a variable within the backtick syntax. <type> or <callout-model> within backticks would be treated as a literal value. Similarly, any quotes that appear inside your backticks will be preserved as quotes.

You didn’t mention it specifically, but I suspect 'callout'$(callout-model)$ may also be causing issues. As written, if <<model>> = “A”…

  • <<callout-model>> = -A
  • inside the backticks, 'callout'$(callout-model)$ = 'callout'-A
  • When the $genesis widget creates your details element, this will give you class="'callout'-A".

But 'callout'-... seems like an unlikely name for a CSS class. Are you sure you really want those single quotes around callout?

Hi Emily.

First of all, thanks for the clarification. There are still things about this topic I need to go into more detail about. You’re right. Based on what you’ve told me in other threads, if I use "" or with variables like this, <type> or <<type>> treats them as their literal value and therefore doesn’t generate the classes I want.
Regarding what you said about 'callout'$(callout-model)$, I understood, and I may be mistaken, that using ‘callout’ was used to enter the text string, or was that just with \define?

The classes as I have them in the CSS are: .callout, .callout-literal, and .callout-literalb.

When @EricShulman told me about the problem, I tried it and saw that it set the main class to .callout, but it turns out you’re right. The secondary classes (-lateral) aren’t being picked up, and I don’t know why…

Here you can see that I have model=lateral as the value, and it still has the .callout class. And the variable check table I have tells me that callout-model is doing it correctly.

I tried this variant, and it works: $values=$(type)$ [[callout]addsuffix<callout-model>]

Best regards.

Try removing the single quotes around callout.

I’m not sure where the miscommunication happened, but I can’t think of any scenarios in which this would be necessary. And when you’re using the backtick syntax in particular, everything that isn’t either a $(variable)$ or a ${ [[filter string]] }$ will be included literally, as it appears between the backticks — including spaces and quotation marks. This means that you should never use quotes inside backticks unless you want them to appear in your output.

I actually wouldn’t expect this to work at all, if you omitted ${ }$ around the filter as that example suggests. The following should work, though there’s not much benefit to using backticks over {{{ }}} syntax at this point…

$values=`$(type)$ ${ [[callout]addsuffix<callout-model>] }$`

The simplest solution is just to use the code Eric provided without the quotes:

$values=`$(type)$ callout$(callout-model)$`

Edit: Just noticed…

Your screenshot shows model:"lateral", but it should probably be model:"literal" to produce .callout-literal.

1 Like

Hi Emily.

Clearly, removing the single quotes from callout worked.

Regarding the single quotes for a string, it wasn’t something you told me; I probably saw it in another thread, or in another piece of code, and misinterpreted it. I’ve already written it down for the next time I have a question. :sweat_smile:

Well, in the end, the code works, just a matter of computer science… :man_shrugging: And the variant you provided also works, so now I have three ways to do it.

Regarding the secondary classes of .callout, they’re actually -lateral, not .literal, a matter of the translator…

Thanks as always for everything.

Hi Eric.

I have a problem with the alternative method because I have to have [<type>] and callout[<callout-model>] separately. I tried: $values={{{ [<type>] [callout<callout-model>] +[join[ ]] }}} but it doesn’t work.

Where callout is a word and type and callout-model are variables.

Regards.

re-read my previous response…

I specifically separated the [[callout]] text from the [<callout-model>] variable, like this:

$values={{{ [<type>] [[ callout]] [<callout-model>] +[join[]] }}}

Note that I also included a leading space in the callout text, so that the result has a space between the type value and the callout value.

To make that important space more apparent, you could write the filter like this:

$values={{{ [<type>] [[ ]] [[callout]] [<callout-model>] +[join[]] }}}

-e

1 Like

Hi Eric.

I made a mistake writing your code by hand, which is why it was failing. Everything’s fine now.

Thank you very much.