Custom Fields
Support MB Views Use the result of a shortcode as a variable

  • Creator
  • #33170


    I have a third-party plugin that imports data from external sources.
    The plugin's shortcode works fine in Views for displaying data.

    But I need to make some operations on the data and I'm having some difficulties.

    When I do this:

    {% set my_var %}
    {% endset %}

    it will display the shortcode result as a number on the front-end, as expected.
    However, in reality my_var is still equal to the text [my_shortcode], so I cannot do mathematical operations on it or save it to a custom field.

    Is there a way to execute the shortcode first, and then have the shortcode's result as a variable (number)?
    I have tried mb.do_shortcode('[my_shortcode]') but it doesn't seem to work...


Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #33171

    I suppose the shortcode should be evaluated before rendering the template, but I don't know how to achieve that. Perhaps there is a custom function for that?

    Long Nguyen

    Hi Tom,

    I think you can create a function that returns a value in PHP code, then assign it to a variable in Twig. Refer to the documentation

    {% set my_function = mb.my_function() %}

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.