Jak v stringu nahradit Latte makra pred vypisanim?
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.

- hizo
 - Člen | 48
 
Zdravim, mam tento problem: potrebujem z DB vytiahnut fotky v tvare: src=„{$basePath}/img/…“ a chcem aby sa $basePath nahradil za to za co ma a aby sa mi do kodu nedalo {$basePath}. Skusil som StringTemplate no nechce to ist. Subory vyzeraju takto:
<?php
class StringTemplate extends Nette\Templating\Template
{
        public $content;
        /**
         * Renders template to output.
         * @return void
         */
        public function render()
        {
                $cache = Nette\Environment::getCache('StringTemplate');
                $key = md5($this->content);
                $content = $cache[$key];
                if ($content === NULL) { // not cached
                        if (!$this->getFilters()) {
                                $this->onPrepareFilters($this);
                        }
                        $cache[$key] = $content = $this->compile($this->content);
                }
                $this->__set('template', $this);
                Nette\Utils\LimitedScope::evaluate($content, $this->getParams());
        }
}
?>
a
<?php
class DefaultPresenter extends \BasePresenter
{
    protected $podnadpis;
    protected $content;
    public function handleClick($page) {
        $data = DB::getContent($page);
        $this->podnadpis = $data['h2_tag'];
        $this->content = $data['content'];
        if($this->isAjax()) {
            $this->invalidateControl('content');
            $this->invalidateControl('script');
        }
    }
    public function renderDefault() {
        $this->template->podnadpis = $this->podnadpis;
        $sablona = new \StringTemplate();
        $sablona->presenter = \Nette\Environment::getApplication()->getPresenter();
        $sablona->registerFilter(new \Nette\Latte\Engine);
        $sablona->content = $this->content;
        $this->template->content = $sablona;
    }
}
?>
Debugger ukazuje ze $this->template->content je NULL neviem preco, ked skusim $this->template->content = $sablona->__toString() tak ukazuje ze content je len prazdny string.
skusal som to aj bez StringTemplate nejak takto:
<?php
public function renderDefault() {
        $this->template->podnadpis = $this->podnadpis;
	$parser = new \Nette\Latte\Parser();
	$this->template->content = $parser->parse($this->content);
?>
no to zase vyhadzuje chybu Unknown macro {=} aj ked $this->content obsahuje len „{$basePath}“. nikto nema podobny problem?