Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to Separate Variables and Blocks #2444

Open
thomasb88 opened this issue Aug 26, 2023 · 2 comments · May be fixed by #2448
Open

Allow to Separate Variables and Blocks #2444

thomasb88 opened this issue Aug 26, 2023 · 2 comments · May be fixed by #2448

Comments

@thomasb88
Copy link

Is your feature request related to a problem? Please describe.

In TemplateProcessor.php, the following characters are defined

protected static $macroOpeningChars = '${';

protected static $macroClosingChars = '}';

And are used for:

  • Cloning Blocks
  • Replacing Variables (through ensureMacroCompleted)

Then the cloning blocks macro should be replaced by '' if only used to manage blocks.

It is even more annoying if you want to use a variable that is used inside a block to duplicate a block...

Describe the solution you'd like

Allow to define different characters for variables and blocks

Describe alternatives you've considered

No generic way to distinguish between blocks and variable in an automated way, with no assumption in the document

Additional context

My goal is to define the way the template is filled from the template itself, and not from any PHP code.

@glaszig glaszig linked a pull request Aug 29, 2023 that will close this issue
3 tasks
@thomasb88
Copy link
Author

I give example for this request:

  • Assume you have a list of sports players with information about them
  • You want to make a template that will define a kind of summary for 1 player only
  • Then you want to generate the document with the summary for all player, 1 by page
  • You have to clone a surrounding block in your template, then fill the data for each instance of player

From now, you have to call on your php code cloneBlock, then setValue, that means you have to know when you code with pattern is block and which one is variable. I would call it PHP code driven.

If you define in a different way blocks and variable, then you can make generic code that will list the document blocks and variables, and apply some processing, whatever the document will be. I would call it document driven.

Note it can be done by searching closing pattern (variables are blocks without closing pattern), but when you use the same name for a block and a variable (that is to say when you write inside the block a data that is also related to the number of data instance, then this rule begins to be more complicated to implement.

@thomasb88
Copy link
Author

Another point. For a real word template document processing, the block management order is important to manage complexity.

Not separating block and variable means variables are blocks that are not closes. Which means errors in blocks definition (let say 1 letter typing error) means the blocks will be understood as 2 variables...and not as an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant