Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
escape out from eval: resource.

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
Pokute
Smarty n00b


Joined: 22 Feb 2013
Posts: 1

PostPosted: Fri Feb 22, 2013 1:59 am    Post subject: escape out from eval: resource. Reply with quote

UPDATE
Forgot extends: but it seems that extends:eval: doesn't work.
Code:
$smarty->fetch("extends:eval:{block name=\"table_data_body\"}{/block}|file:games_table_contents.tpl");
fails.

UPDATE
I actually found that I don't have to generate a separate template file in php for loading in smarty, but there is a problem:

Code:
$smarty->fetch("eval:{block name=\"table_data_body\"}{/block}|file:games_table_contents.tpl");
Doesn't work as fetch doesn't recognize the pipe and won't try to load the file.

Old post:

I want a possibility to get specific block from a template file in php.

Use case (written directly here so it won't work as is):

games.tpl:
Code:
{include file="extends:list_table_container.tpl|games_table_contents.tpl" scope='global'} {* Yeah, "colliding beams" here but not real code. Unimportant anyway. *}


list_table_container.tpl:
Code:
<table id="{block name="table_id"}{/block}">
<thead>
  {block name="table_head"}{/block}
</thead>
<tbody>
  {block name="table_body"}{/block}
</tbody>
</table>
<div id="reload_button">Reload</div>
<script>
 // reloads table contents
  $("#reload_button").click (function () {
     $.ajax ("{block name="table_reload_url"}{/block}", {
       success: function (data)
       {
          $("#{block name="table_id"}{/block} tbody").html (data) ;
       }
     });
  });
<script>


games_table_contents.tpl:
Code:

{block name="table_id"}games_table{/block}
{block name="table_head"}
<tr>
  <th>Name</th><th>Genre</th>
</tr>
{/block}
{block name="table_body"}
{foreach from=$games_list item="game"}
<tr>
  <td>{$game.name}</td><td>{$game.genre}</td>
</tr>
{/foreach}
{/block}
{block name="table_reload_url"}games_reload.php{/block}


games.php:
Code:
  $smarty->assign ('games_list', $games_list);
  $smarty->display ('games.tpl');


games_reload.php:
Code:
  $smarty->assign ('games_list', $games_list);
  $smarty->display_block ('games_table_contents.tpl', 'table_body'); // Doesn't work currently. How do I get output only one block?


Above code allows me to use same table template with different content and when reloading, requesting only the table data and not having any scripts re-run. All table content is in one template file. But that single template file backfires when I can't get a single block out from a template.

One way I can do this is by dynamically generating a template with only '{block name="table_body"}{/block}' inside php (and will do this meanwhile), but that's ugly and I'd really like to get this feature added or even just discussions on best ways to do this or suggestions on alternative approaches.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP