Feature #7608

Configurable shorthand/object accessor delimiters

Added by Lienhart Woitok over 5 years ago. Updated over 1 year ago.

Status:New Start date:2010-05-03
Priority:Could have Due date:
Assigned To:- % Done:

0%

Category:Core
Target version:-
Has patch:Yes

Description

See Mailinglist Thread "About limitations in Fluid"

For some output formats (like LaTeX) it is not comfortable to use { and } for shorthand syntax as these symbols are used by the target language. Therefore, the possibility to configure the open and close symbols for short hand syntax is necessary.

Attached patch provides this.

fluid-shorthandsyntax.patch Magnifier (9.8 kB) Lienhart Woitok, 2010-05-03 15:31

fluid-shorthandsyntax_7608_v2.patch Magnifier (17.5 kB) Bastian Waidelich, 2012-11-26 17:44


Related issues

related to TYPO3.Fluid - Feature #43356: Allow Fluid arrays only in ViewHelper arguments Resolved 2012-11-27
duplicated by TYPO3.Fluid - Feature #11286: Alternative syntax for fluid objects inside JavaScript Closed 2010-12-05

History

#1 Updated by Thomas Deinhamer over 5 years ago

Just my 2 cents, maybe it's nicer to name the variables
$openingShorthandSymbol and $closingShorthandSymbol or
maybe there are even better names for them.

#2 Updated by Jochen Rau about 5 years ago

  • Assigned To set to Sebastian Kurfuerst

#3 Updated by Sebastian Kurfuerst about 5 years ago

  • Project changed from Extbase MVC Framework to TYPO3.Fluid
  • Assigned To deleted (Sebastian Kurfuerst)

#4 Updated by Sebastian Kurfuerst about 5 years ago

  • Priority changed from Should have to Could have

#5 Updated by Bastian Waidelich over 4 years ago

  • Subject changed from Configurable short hand syntax for fluid to Configurable shorthand/object accessor delimiters
  • Category set to Core
  • Branch set to v4 + v5

#6 Updated by Sebastian Kurfuerst about 4 years ago

  • Has patch set to Yes

#7 Updated by Karsten Dambekalns over 2 years ago

One issue with such an approach is: what happens if you change this, and thus break templates included with other people's packages? The delimiter used should be configured in the template, then you could mix it without worries…

#8 Updated by Bastian Waidelich over 2 years ago

Karsten Dambekalns wrote:

One issue with such an approach is: what happens if you change this, and thus break templates included with other people's packages?
The delimiter used should be configured in the template, then you could mix it without worries…

I just thought the same.. it could be set in initializeView for one action only somehow but that would couple controller & view too tightly together. An alternative solution would be a ViewHelper that initializes the parser itself to parse the child nodes – but still we'd need to be able to configure the parser and therefore need something similar to Lienhards solution..

#9 Updated by Bastian Waidelich over 2 years ago

Attached an updated (and slightly adjusted) version of Lienharts patch.
What's missing now is a way to modify the parser configuration from the "outside" (we need that anyways) and a way to specify the opening/closing symbols in the template.
I created a basic test view helper for that:

 1class TestViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {
 2
 3    /**
 4     * @var \TYPO3\Fluid\View\StandaloneView
 5     * @Flow\Inject
 6     */
 7    protected $view;
 8
 9    /**
10     * @param string $openingShorthandSymbol
11     * @param string $closingShorthandSymbol
12     * @return string
13     */
14    public function render($openingShorthandSymbol = '{', $closingShorthandSymbol = '}') {
15        $this->view->setTemplateSource($this->renderChildren());
16        $this->view->setControllerContext($this->renderingContext->getControllerContext());
17        $this->view->assignMultiple($this->templateVariableContainer->getAll());
18
19            // NOTE: This getter doesn't exist yet
20        $templateParser = $this->view->getTemplateParser();
21        $parserConfiguration = $templateParser->getConfiguration();
22        if ($parserConfiguration === NULL) {
23            $parserConfiguration = new \TYPO3\Fluid\Core\Parser\Configuration();
24        }
25        $parserConfiguration->setOpeningShorthandSymbol($openingShorthandSymbol);
26        $parserConfiguration->setClosingShorthandSymbol($closingShorthandSymbol);
27            // NOTE: ...neither does this setter
28        $templateParser->setConfiguration($parserConfiguration);
29
30        return $this->view->render();
31    }
32}

That could be used like

1<x:test openingShorthandSymbol="###" closingShorthandSymbol="###"><![CDATA[
2    ###someObjects -> f:count()###
3]]></x:test>

(note the required CDATA tags for this)

I don't like it. Maybe something like the {namespace ...} syntax would be nicer, but then this can only work per template/partial..

#10 Updated by Bastian Waidelich over 2 years ago

FYI: After discussing this again with Sebastian we still did not find a nice way to configure this. Because it has to be changeable per template/partial/layout it would probably need to be defined in the file or via the upcoming Views.yaml.. For now have a look at #43356 which greatly reduces the clashes if you use Fluid in JavaScript, CSS etc.

#11 Updated by Bastian Waidelich almost 2 years ago

FYI there is a neat little work around using the alias ViewHelper.

So instead of having to use CDATA everywhere to escape curly brackets:

 1<script>
 2var options = <![CDATA[{]]>
 3  foo = "{foo}",
 4  bar = "{bar}
 5<![CDATA[}]]>;
 6function foo() <![CDATA[{]]>
 7
 8<![CDATA[}]]>
 9</script>

you can also put your content in a alias VH:

 1<f:alias map="{l: '{', r: '}'}">
 2<script>
 3var options = {l}
 4  foo = "{foo}",
 5  bar = "{bar}
 6{r};
 7function foo() {l}
 8
 9{r}
10</script>
11</f:alias>

#12 Updated by Wouter Beeftink over 1 year ago

I would love to have an alternative delimiter for fluid tags. Bastian's approach is a great workaround for now.
If it were up to me this ticket should be labelled as should have.

Also available in: Atom PDF