How to use snippet variables?

0
Hi Smart People of Mendix Community,   Help me, I might have a wrong approach on the fairly new page and snippet variables.   My case: I wanted to create a tab container with 2 identical looking datagrids, the first for the tasks in progress, the second for the ones already closed.   My plan was to make a snippet with a variable for the state enum and integrate that variable into the xpath of the data grid 2 within. Which is what I actually did.   But when I try to add a value to the variable on each snippet call, it shows no parameters that could be placed. I've tried to wrap it into a Data view of a helper object (which is actually what I want to avoid) but no difference.   Can you help me how to achieve what was promised as bye bye helper objects?
asked
2 answers
0
  • Snippet variables ≠ free parameters.They depend on an object or primitive value passed from the caller context.A page cannot “inject” an enum literal directly into a snippet.

  • Option A (Recommended – simple and modern):

    • Use a page parameter (e.g. entity TaskHelper with StateEnum attribute).

    • In the main page, create two Data Views, each with its own helper having the desired enum value (“InProgress”, “Closed”).

    • Place your snippet inside each Data View → now the snippet variable can read $currentObject/StateEnum.Only one helper per tab, no microflows, works cleanly.

  • Option B (Microflow source):

    • Each tab’s Data View calls a microflow that returns a helper with the correct enum value.

    • The snippet then uses that variable inside XPath.⚙️ Slightly heavier, but works without manual object creation.

  • Option C (Bypass snippet variable):

    • Keep one generic snippet.

    • Add XPath constraint using [State = '[%CurrentTabValue%]'] dynamically via a context entity or tab-specific data source microflow.⚙️ This gives more flexibility but adds microflow logic.

    • Snippet variables ≠ free parameters.
      They depend on an object or primitive value passed from the caller context.
      A page cannot “inject” an enum literal directly into a snippet.

    • Option A (Recommended – simple and modern):

      • Use a page parameter (e.g. entity TaskHelper with StateEnum attribute).

      • In the main page, create two Data Views, each with its own helper having the desired enum value (“InProgress”, “Closed”).

      • Place your snippet inside each Data View → now the snippet variable can read $currentObject/StateEnum.
        ✅ Only one helper per tab, no microflows, works cleanly.

    • Option B (Microflow source):

      • Each tab’s Data View calls a microflow that returns a helper with the correct enum value.

      • The snippet then uses that variable inside XPath.
        ⚙️ Slightly heavier, but works without manual object creation.

    • Option C (Bypass snippet variable):

      • Keep one generic snippet.

      • Add XPath constraint using [State = '[%CurrentTabValue%]'] dynamically via a context entity or tab-specific data source microflow.
        ⚙️ This gives more flexibility but adds microflow logic.

answered
0

Thanks Uggirala Mentaraju, but all your suggestions need a helper object and that is what I would like to avoid. (Thus the functionality is the same as it used to be with object parameters.)

 

If the only usage of the variable to be able to calculate something on call based on a parameter, that could've been used elsewhere, so I don't really see the difference.

 

I'm still looking for an explanation, how variables in snippets add extra functionality.

answered