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

Twital not working within blocks #74

Open
BergBenji opened this issue Feb 15, 2021 · 4 comments
Open

Twital not working within blocks #74

BergBenji opened this issue Feb 15, 2021 · 4 comments

Comments

@BergBenji
Copy link

BergBenji commented Feb 15, 2021

I started using twital because of its similarities to phptal.
But it seems not to work in Blocks.

Blockcode:

{% block textelement %}
<div class="form-group {{fiel.getAttributeByName('groupclass') | default(NULL)}}">
    <label for="" class="control-label">{{fiel.label |raw}} <span t:if="fiel.validation">*</span></label>
    <div t:if="fiel.errors" t:for="item fiel.errors">
        <span>{{item |raw}}</span>
    </div>
    {{fiel.generateElement() |raw}}
</div>
{% endblock textelement %}

The normal TWIG works, but the Twital elements (t:if, t:for) not.
I tried to implemente the template several ways but it wont work. Any ideas?

I need to render the blocks seperatly and use this code:
$tpl = $this->twig->load($tpl); $res = $tpl->renderBlock($block, array_merge($this->vars, $vars));

Any ideas whats wrong?

@goetas
Copy link
Owner

goetas commented Feb 15, 2021

Do you know it twital is configured at all? how are you loading Twital?

@BergBenji
Copy link
Author

BergBenji commented Feb 15, 2021

In the Templates everywhere twital is working.
Only if i load the block by "renderBlock" it dont work.

I testet it with following code:
<p t:if="username">Username exists</p>
And it worked.
On other places i used the t:for and it work too.
Here is the implementation:
$this->fileloader = new FilesystemLoader([tpldir]); $this->twitalloader = new TwitalLoader($this->fileloader); $this->twitalloader->addSourceAdapter('/\.wsdl$/', new XMLAdapter()); // handle .wsdl files as XML $this->twitalloader->addSourceAdapter('/\.html$/', new HTML5Adapter()); $this->twitalloader->addSourceAdapter('/\.twig$/', new HTML5Adapter()); $this->twitalloader->addSourceAdapter('/\.html\.twig$/', new HTML5Adapter()); $this->twitalloader->addSourceAdapter('/\.twital\.html$/', new HTML5Adapter()); $this->twig = new Environment($this->twitalloader, [ 'debug' => true, ]);

@BergBenji
Copy link
Author

image
image
image

@BergBenji
Copy link
Author

Block within a template also works.
image
So it only not works if the block is loaded by renderBlock.
Hope that helps

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

No branches or pull requests

2 participants