• Resolved mraiaamcham

    (@mraiaamcham)


    Hi, community!

    I’m trying to get information from a view in my Contacts Entity but it seems that using a variable on the parameters field is not working with Twig templates. We extract the email of a list of clients using a PHP function inside a shortcode, it returns the email as a string. Here is our code, inserted using the Code Module from Divi (theme) :

    [msdyncrm_twig]

    {% set emailuser = “[get_email]” %} // The [get_email] is the custom shortcode. The sentence with quotes returns the email as a string, we checked with dump().

    {% view entity=”contact” name=”EXAMPLE VIEW” count=”1″ parameters=[emailuser] %} // We use the variable emailuser to indicate that there is the email of the user as a string

    {% for recordId, record in entityview.rows %}

    Hi, {{ record.fullname.value }}

    {% endfor %}

    {% endview %}

    [/msdyncrm_twig]

    The problem is that the variable “emailuser” inside the parameters field is not working because I never get the information. If we execute the function {{dump(emailuser)}} it shows the email as a string.

    We set the filter on the view as {0} and, if we use any email (for example, “[email protected]”), we can display de information of the contact.

    Its possible to pass a variable as a parameter in Twig’s view template?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author alexacrm

    (@alexacrm)

    Hi @mraiaamcham

    thanks for raising the issue… emailuser object should work… Hmmm… Can you try {% view ... parameters=[{{emailuser}}] %}?

    Thanks

    Thread Starter mraiaamcham

    (@mraiaamcham)

    Hi!

    This is the output of trying [{{emailuser}}]:

    Unexpected error: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token “punctuation” of value “{” in “template…” in line 4

    Thanks!

    Plugin Author alexacrm

    (@alexacrm)

    @mraiaamcham

    we retested the functionality and it’s supposed to work.

    Does this one work as expected?

    [msdyncrm_twig]
    {% set emailuser = "[email protected]" %}
    {% view entity="contact" name="EXAMPLE VIEW" count="1" parameters=[emailuser] %}
    ...

    If yes then I suspect it’s timing of the shortcode processing, i.e. your shortcode gets processed after the twig one.

    Thread Starter mraiaamcham

    (@mraiaamcham)

    Hi!

    Yes! When I set emailuser = “[email protected]” it works.

    It’s possible to change the timing on the shortcode to get processed before the twig one?

    Thanks!

    Plugin Author alexacrm

    (@alexacrm)

    @mraiaamcham as per https://stackoverflow.com/questions/4773186/shortcodes-inside-a-shortcode-wordpress, shortcodes do not nest. One of the options is to replace [get_email] shortcode with a custom twig function (where you can use do_shortcode call), see our KB Add custom functions and variables to Twig. Something like

    function get_email_twig( $twigEnv ) {
      $getemail = new \Twig\TwigFunction(
        'get_email', function( ) {
          return do_shortcode('[get_email]');
      } );
     
      $twigEnv->addFunction( $getemail );
     
      return $twigEnv;
    }
     
    add_action('wordpresscrm_after_twig_ready', 'get_email_twig', 10, 1);

    and then simply

    {% set useremail = get_email() %}

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Variables in parameter field (view)’ is closed to new replies.