Viacnasobne include block zo suboru
- duskohu
- Člen | 778
Caute mam nejake pole sablon, prechadzam tymto zoznamom a potrebujem vykreslit konkretne bloky z tychto sablon, je to mozne? Tento priklad nefunguje stale mi nacita bloky len z 1 template. Proste potrebujem na viac miestach nacitat bloky z viacerich sablon.
$templates = array(
'some/path/template1.latte',
'some/path/template2.latte',
);
//
{foreach $templates => $template}
{includeblock $template}
{include leftBanner}
{/foreach}
//a na inom mieste
{foreach $templates => $template}
{includeblock $template}
{include rightBanner}
{/foreach}
// some/path/template1.latte
{define leftBanner}
template1-leftBanner
{/define}
{define rightBanner}
template1-rightBanner
{/define}
// some/path/template2.latte
{define leftBanner}
template2-leftBanner
{/define}
{define rightBanner}
template2-rightBanner
{/define}
Editoval duskohu (15. 2. 2017 17:35)
- duskohu
- Člen | 778
@CZechBoY No je to trosku komplikovanejsie, ale skusim. Jedna sa
v podstate o rozsirenie nejakej komponenty ktora ma v sebe formular.
Mam komponentu ktora ma v sebe formular a na zaklade nejakej logiky mam pre
tuko komponentu naplnenu $this->metaProviders
a tieto providre
si vytiahnem z $postMetaProviderContainer
V komponente
/**
* @param IComponent $presenter
*/
protected function attached($presenter) {
parent::attached($presenter);
if ($presenter instanceof Presenter) {
$postMetaProviderContainer = $this->postMetaProviderContainer;
foreach ($this->metaProviders as $metaProviderName) {
/** @var IPostMeta|NULL $provider */
$provider = $postMetaProviderContainer($metaProviderName);
if ($provider) {
$this->postMetaProviders[$metaProviderName] = $provider->create($this);
// $this->postMetaProviders // preda sa do sablony aby som si mohol vytiahnut template
}
}
}
}
A ten jeden z providerov:
class MetaContentProvider implements IPostMeta {
/** @var string */
public $templateFile;
public function __construct() {
$this->templateFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MetaContentProvider.latte';
}
/**
* @param PostFormControl $control
* @return $this
*/
public function create(PostFormControl $control) {
$control->onBeforeAddFlush[] = array($this, 'processAdd');
$control->onBeforeEditFlush[] = array($this, 'processEdit');
$form = $control->getComponent('form');
$form->onValidate[] = array($this, 'processValidate');
$metaContentProvider = $form->addContainer('metaContentProvider');
$metaContentProvider->addTextArea("content", "Obsah")
->setAttribute('data-ckeditor');
return $this;
}
/**
* @param Form $form
*/
public function processValidate(Form $form) {
//$form->addError('ddddddddddddd');
}
/**
* @param PostFormControl $control
* @param BasePost $entity
* @param Form $form
*/
public function processAdd($control, $entity, $form) {
$values = $form->getValues();
//bd($values);
}
/**
* @param PostFormControl $control
* @param BasePost $entity
* @param Form $form
*/
public function processEdit($control, $entity, $form) {
$values = $form->getValues();
//bd($values);
}
}
Nasledne mam aj sablonu v ktorej renderujem tento prvok ktory som podstrcil
providerom, podla toho v akom bloku baseArea
, alebo
sidebarArea
tak v tej casti formu sa vyrenderuje.
{define baseArea}
{formContainer metaContentProvider}
<div class="space-3"></div>
<div class="form-group">
{label content class=>"col-sm-2 control-label no-padding-right"/}
<div class="col-sm-10">
{input content class=>"form-control col-xs-12 col-sm-5"}
<div class="form-alert bottom" n:if="$form['metaContentProvider']['content']->error">
<div class="arrow"></div>
<div class="form-alert-content">{$form['metaContentProvider']['content']->error}</div>
</div>
</div>
</div>
{/formContainer}
{/define}
{define sidebarArea}
//...keby som chcel renderovat v inej casti
{/define}
V sablonae formu by som chcel v v castiach baseArea
, alebo
sidebarArea
vyrenderovat blok konkretneho providera.
A na tejto casti som sa zasekol …
{foreach $postMetaProviders as $name => $provider}
{includeblock $provider->templateFile}
{include sidebarArea}
{/foreach}
// niekde inde
{foreach $postMetaProviders as $name => $provider}
{includeblock $provider->templateFile}
{include baseArea}
{/foreach}
Editoval duskohu (15. 2. 2017 20:50)
- duskohu
- Člen | 778
Toto riesenie, sa mi uplne nepaci, lebo nemozem sablone providru, predat
z providru ziadne variables.
Takze este zvazujem ako to zrefaktorujem. Uvazoval som ze provider bude control
ktory dam ako daaComponent hlavnej komponente s formularom, ale to
nevyrenderujem potom v sablone provider element pre ten form.
Proste tu som sa zamotal.
Editoval duskohu (15. 2. 2017 22:04)