Hi guys.
Here’s the question.
Suppose I want to do some client-side template rendering, but still use Yii’s routing functions for url generation.
So the HTML can look something like this (depends on templating engine):
<script id="tmpl" type="text/x-something">
<li>
<a href="<?= Url::toRoute(['controller/action', 'id' => !!! HERE COMES THE TROUBLE !!!]) ?>">
{{:name}}
</a>
</li>
</script>
The thing is, the $id for this route is unknown until render happens.
It would be great if I could do this:
<script id="tmpl" type="text/x-something">
<li>
<a href="<?= Url::toRoute(['controller/action', 'id' => '{{:id}}']) ?>">
{{:name}}
</a>
</li>
</script>
but brackets getting url-escaped, so it’s not working.
As for now, I’m using “placeholder” (<?= Url::toRoute([‘controller/action’, ‘id’ => ‘id’]) ?>) + extra js function to achieve the result, but this doesn’t look good to me.
Any ideas?