Last active
December 14, 2015 00:09
-
-
Save fsuter/4997023 to your computer and use it in GitHub Desktop.
Fluid view helpers and multiple partials invocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$output26 = ''; | |
$output26 .= ' | |
<ol> | |
<li> | |
'; | |
// Rendering ViewHelper Tx_Fluid_ViewHelpers_RenderViewHelper | |
$arguments27 = array(); | |
$arguments27['partial'] = 'DmdeMobile/TrainingDetail'; | |
// Rendering Array | |
$array28 = array(); | |
$array28['formation'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.formation', $renderingContext); | |
$array28['lieu'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.lieu', $renderingContext); | |
$array28['conditionsAdmission'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.conditionsAdmission', $renderingContext); | |
$array28['remarques'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.remarques', $renderingContext); | |
$arguments27['arguments'] = $array28; | |
$arguments27['section'] = NULL; | |
$arguments27['optional'] = false; | |
$renderChildrenClosure29 = function() use ($renderingContext, $self) { | |
return NULL; | |
}; | |
$viewHelper30 = $self->getViewHelper('$viewHelper30', $renderingContext, 'Tx_Fluid_ViewHelpers_RenderViewHelper'); | |
$viewHelper30->setArguments($arguments27); | |
$viewHelper30->setRenderingContext($renderingContext); | |
$viewHelper30->setRenderChildrenClosure($renderChildrenClosure29); | |
// End of ViewHelper Tx_Fluid_ViewHelpers_RenderViewHelper | |
$output26 .= $viewHelper30->initializeArgumentsAndRender(); | |
$output26 .= ' | |
</li> | |
<li> | |
'; | |
// Rendering ViewHelper Tx_Fluid_ViewHelpers_RenderViewHelper | |
$arguments31 = array(); | |
$arguments31['partial'] = 'DmdeMobile/TrainingDetail'; | |
// Rendering Array | |
$array32 = array(); | |
$array32['formation'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.formation2', $renderingContext); | |
$array32['lieu'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.lieu2', $renderingContext); | |
$array32['conditionsAdmission'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.conditionsAdmission2', $renderingContext); | |
$array32['remarques'] = Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode::getPropertyPath($renderingContext->getTemplateVariableContainer(), 'dmde.remarques2', $renderingContext); | |
$arguments31['arguments'] = $array32; | |
$arguments31['section'] = NULL; | |
$arguments31['optional'] = false; | |
$renderChildrenClosure33 = function() use ($renderingContext, $self) { | |
return NULL; | |
}; | |
$viewHelper34 = $self->getViewHelper('$viewHelper34', $renderingContext, 'Tx_Fluid_ViewHelpers_RenderViewHelper'); | |
$viewHelper34->setArguments($arguments31); | |
$viewHelper34->setRenderingContext($renderingContext); | |
$viewHelper34->setRenderChildrenClosure($renderChildrenClosure33); | |
// End of ViewHelper Tx_Fluid_ViewHelpers_RenderViewHelper | |
$output26 .= $viewHelper34->initializeArgumentsAndRender(); | |
$output26 .= ' | |
</li> | |
</ol> | |
'; | |
return $output26; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*************************************************************** | |
* Copyright notice | |
* | |
* (c) 2013 Francois Suter <[email protected]> | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
***************************************************************/ | |
require_once(t3lib_extMgm::extPath('vd_ocosp', '/class/Ocosp/Wiki.php')); | |
/** | |
* Wrapper around Ocosp_Wiki class | |
* | |
* = Examples = | |
* | |
* <code title="Simple Loop"> | |
* <vd:wiki parseText="true" parseLinks="false"> | |
* - foo | |
* - bar | |
* </vd:wiki> | |
* </code> | |
* <output> | |
* <ul> | |
* <li>foo</li> | |
* <li>bar</li> | |
* </ul> | |
* </output> | |
* | |
* @author Francois Suter <[email protected]> | |
* @package TYPO3 | |
* @subpackage tx_vdocosp | |
*/ | |
class Tx_VdOcosp_ViewHelpers_WikiViewHelper extends Tx_Fluid_ViewHelpers_ForViewHelper { | |
/** | |
* Sorts list of items according to given criteria and loop on them for rendering | |
* | |
* @param boolean $parseText TRUE if text must be parsed (for bullet list structures) | |
* @param boolean $parseLinks TRUE if text must be parsed for links | |
* @return string Rendered string | |
* @api | |
*/ | |
public function render($parseText = FALSE, $parseLinks = FALSE) { | |
$parseText = (boolean)$parseText; | |
$parseLinks = (boolean)$parseLinks; | |
// Render the content first, to apply transformations to it | |
$content = $this->renderChildren(); | |
if ($parseLinks) { | |
$content = Ocosp_Wiki::parseForUrls($content); | |
} | |
if ($parseText) { | |
$content = Ocosp_Wiki::parseTxt($content); | |
} | |
return nl2br($content); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{namespace vd = Tx_VdOcosp_ViewHelpers} | |
<f:if condition="{formation}"> | |
<div> | |
<vd:wiki parseText="true">{formation}</vd:wiki> | |
</div> | |
</f:if> | |
<f:if condition="{lieu}"> | |
<h5><f:translate key="location" /></h5> | |
<div> | |
<vd:wiki parseText="true">{lieu}</vd:wiki> | |
</div> | |
</f:if> | |
<f:if condition="{conditionsAdmission}"> | |
<h5><f:translate key="enrollment_requirements" /></h5> | |
<div> | |
<vd:wiki parseText="true">{conditionsAdmission}</vd:wiki> | |
</div> | |
</f:if> | |
<f:if condition="{remarques}"> | |
<h5><f:translate key="remarks" /></h5> | |
<div> | |
<vd:wiki parseText="true">{remarques}</vd:wiki> | |
</div> | |
</f:if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{namespace vd = Tx_VdOcosp_ViewHelpers} | |
<f:layout name="Default" /> | |
This template displays the detail view for a "Des Métiers - Des Ecoles" entry | |
<f:section name="main"> | |
<h3>{dmde.professionAffichage}</h3> | |
<div> | |
<vd:wiki parseText="true">{dmde.description}</vd:wiki> | |
</div> | |
<h4><f:translate key="training" /></h4> | |
<f:if condition="{dmde.formationDesc}"> | |
<div> | |
<vd:wiki parseText="true">{dmde.formationDesc}</vd:wiki> | |
</div> | |
</f:if> | |
<f:if condition="{dmde.formation2}"> | |
<f:then> | |
<ol> | |
<li> | |
<f:render partial="DmdeMobile/TrainingDetail" arguments="{formation: dmde.formation, lieu: dmde.lieu, conditionsAdmission: dmde.conditionsAdmission, remarques: dmde.remarques}" /> | |
</li> | |
<li> | |
<f:render partial="DmdeMobile/TrainingDetail" arguments="{formation: dmde.formation2, lieu: dmde.lieu2, conditionsAdmission: dmde.conditionsAdmission2, remarques: dmde.remarques2}" /> | |
</li> | |
</ol> | |
</f:then> | |
<f:else> | |
<blockquote> | |
<f:render partial="DmdeMobile/TrainingDetail" arguments="{formation: dmde.formation, lieu: dmde.lieu, conditionsAdmission: dmde.conditionsAdmission, remarques: dmde.remarques}" /> | |
</blockquote> | |
</f:else> | |
</f:if> | |
</f:section> |
What do you mean? A section for each variable? But the conditions are there to assure that there's no output if the variable is empty. So I would still need the conditions even inside each section, right?
Hi François,
you're extending Tx_Fluid_ViewHelpers_ForViewHelper instead of AbstractViewHelper – I guess this is your problem as in the cached Template the renderStatic() method of the ForViewHelper will be called.
As answered in the ML, copy and paste error. Thanks for spotting it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi François,
Suggestion: use
f:section
inside the Partial template instead of conditions. Combine as such:<f:render partial="..." section="..." arguments="..." />
. This will not only be cleaner and more efficient - it will also cache each section to an individual cached file, making sure your variables become separated ;)Hope this helps!
Cheers,
Claus