I'm cooking an extension using EXTbase and fluid for TYPO3 v7+ .
I'm here.. because I'm rendering my fluid templates based on certain controller conditions.Under a condition I want something like the html code being rendered from a user supplied template file.
I've used jQuery to bypass the situation..
<script>
$(function(){
$("#some_div_id").load("template_file.html");
});
</script>
Guess what.. I got the result I expected,but not really..
<div class="clearfix">
<ul id="image-gallery" class="gallery list-unstyled cS-hidden">
<f:for each="{slider}" as="user" key="label" iteration="iterator">
<li data-thumb="{user.src}">
<f:image crop="{user.crop}" treatidasreference="true" src="{user.filepath}" alt="{user.title}" style="width:100%; height:auto;"></f:image>
<f:if condition="{config.metadata.switch}!= 0">
<f:if condition="{user.title}">
<p class="light-caption" style="background: {config.metadata.opacity}; color: {config.metadata.color}; font-size: {config.metadata.size}%; text-align:{config.metadata.align};">{user.title}</p>
</f:if>
</f:if>
</li>
</f:for>
</ul>
</div>
This above is the code resulted.. See, the TypoScript variables are untouched.Little embarrassing.!!
Searching round the clock for an answer.Any ideas ?
What you need is a partial: https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Render.html
In your Fluid template you would add a condition based on the variables provided from the controller
<f:if condition="{showPartial1}">
<f:render partial="SomePartial1" arguments="{_all}" />
</f:if>
<f:if condition="{showPartial2}">
<f:render partial="SomePartial2" arguments="{_all}" />
</f:if>
The partials are typically added in the Partials folder (should be in the same folder as your Templates folder) like that
Partials/SomePartial1.html
Partials/SomePartial2.html
In your controller action you can use $this->view->setTemplate('myDynamicTemplateName'); to use a different template than suggested by the action name.
Refer to: https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_fluid_1_1_view_1_1_template_view.html#a9c46c7bfe6a39b26478a2f37aec38d80
You are loading the plain template from the server - there is no PHP code involved that could render your template. You need to send the request in a way that the controller action is executed, renders the template, and then sends the rendered result to you.
The simplest way to do this is to use the extension typoscript_rendering. To use it, render a link to your controller action using the ViewHelper that the extension provides. It would look like this:
{namespace helhum=Helhum\TyposcriptRendering\ViewHelpers}
// Other stuff
<helhum:uri.ajaxAction action="actionName" controller="YourController"/>
Maybe you need to add other parameters - the ViewHelper takes the same parameter that the other f:uri.*-ViewHelpers take. In your JS, you can then send a request to that link (maybe put the link into some data-attribute), and will receive the rendered template.
Related
When i create a new Post and write in the excerpt, the post image on the news page just dissappears . It only works if i have no excerpt. Also .. How can i create new posts with existing classes already written in my css?
Without the excerpt ir works just fine. Showing image and text that i add on the post.
My code
<section id="content">
<div class="content-wrap">
<div class="container clearfix">
<div class="row"> {% component 'blogPosts' %}
</div>
</div>
</div>
</section><!-- #content end -->
When not defining an excerpt, a summary attribute is appended to the model. See https://github.com/rainlab/blog-plugin/blob/master/models/Post.php#L344 . If your content starts with an image, it might be that the summary function kicks in and generates the image.
As for the CSS part
I think you're looking to override the partial set by {% componenent 'blogPosts' %}. As per the docs (https://octobercms.com/docs/cms/components#overriding-partials)
All component partials can be overridden using the theme partials. If
a component called channel uses the title.htm partial. We can override
the partial by creating a file in our theme called
partials/channel/title.htm.
Alternatively you can cmd / ctrl + doubleclick to expand the default component markup inside the CMS editor.
In this way you can edit your markup to match your theme.
If you want to override markup there is really easy way. for image #CptMeatball added proper answer you can check that out.
This way you have full control on mark-up and you can edit it.
1. Click on expand component it will reveal mark-up of component
2. Now you can add your own markup and edit it.
if any doubt please comment.
On a page and all of its subpages, I want to include a certain section. In my default template I added this:
<div class="container">
<f:render section="Productsearch"/>
</div>
But I want this section to only be included on certain pages. How can I achieve this?
Use a different layout on these pages. You can probably do this by using a setting (plugins.tx_yourext.settings.layoutName = Layout2.html), and then using that in the template:
<f:layout name="{settings.layoutName}"/>
The layout on the special pages renders the section, the usual layout does not render it.
EDIT: You could also just use a condition in the layout. Set plugins.tx_yourext.settings.showProductSearch = 1 (or 0) on the pages, preferrably using a TypoScript constant. Then use it in a condition:
<f:if condition="{settings.showProductSearch}">
<f:render section="Productsearch"/>
</f:if>
using php's include is possible to include part of another page without including all that entire content of that page?
From pageX.php i want Div #A not div #B the whole pageX.php
<div id="A">
<p>Don't show me</p>
</div>
<div id="B">
<p>Display Me</p>
</div>
i'm aware of JQuery's ajax Load but im wondering if there's a method like that in php.
I am not aware of any function that can include a specific part of a php file but typically this can be achieved in two ways.
Split your UI component markups into separate files so that can be included separately and easily re-used in many places. (example here)
Have all the UI components markups as different functions in a common file which can be called easily.
function printDivA() {
echo <<< DIV_A
<div id="A">
<p>Don't show me</p>
</div>
DIV_A;
}
I'm using .ini files to render my menu.
Bootstrap
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/menu.ini', 'nav');
$nav = new Zend_Navigation($config);
$view->navigation($nav);
layout.phtml
<?php echo $this->navigation()->menu()->setMaxDepth(3) ?>
My target to reach:
<ul class="navigation" id="navigation">
<li>
<a id="menu-1" href="/">Home</a>
</li>
</ul>
How to set id="navigation" for the first <ul> occurence instead of class="navigation"?
Now I've got only <ul class="navigation"> and i want to <ul id="navigation"> or <ul class="navigation" id="navigation">
You would need to setup a custom view helper, in your code library, not under Zend_.
Maybe something like GZ_View_Helper_Navigation_Menu2
And then depending on how you want to configure the addition of this new view helper path, something like this in your bootstraps initView:
$view->addHelperPath('GZ/View/Helper/', 'GZ_View_Helper');
Or, if using Application and Resources you can setup that via the ini too with:
resources.view.helperPath.GZ_View_Helper = "GZ/View/Helper"
Your lib GZ of course needs to be on PHP's include path.
When rendering you would change the call to:
<?= $this->navigation()->menu2()->setMaxDepth(3) ?>
Although I think you can also assign a default view helper (can't find it in docs right now) to Navigation and just call
<?= $this->navigation ?>
Related: How do I extend the Zend Navigation Menu View Helper?
You can do this with jQuery:
$('document').load(function(){
$("body > ul:first-child").attr('id', 'navigation');
})
EDIT:
After reading your comments, I noted that you are using Mootols library, so you can do the jQuery equivalent, something like this:
window.addEvent('domready', function() {
var myMenu = new MenuMatic({ orientation:'vertical' });
myMenu.getElement('ul').set('id', 'navigation');
});
I've thought about doing this method a lot myself. I often create multiple navigation objects in my Zend Framework projects.
Instead, I would submit a different answer. In your view, enclose your call to the navigation output inside of the HTML5 nav element. This makes it both semantically clearer AND allows you to add your own ID to each section easily. So, try this:
<nav id="navigation"><?php echo $this->navigation()->menu()->setMaxDepth(3) ?></nav>
An interesting thing to note - if you only have 1 navigation element on the page, you won't even need the ID then. You can target it using the nav element in your css... for example, to make all ul's in the navigation have zero margin, you might do this in css:
nav ul { margin: 0px }
In ZF 1.12 (don't know from which version exactly) there is one methode for that:
$this->navigation()->menu()->setUlId('navigation')->setMaxDepth(0);
I am currently working on moving an expression engine site from one server to another and i noticed one issue i am having a hardtime debugging. When i upload an logo image all seems fine but the index.php page that the logo is displayed on it has this code
{embed="shared/head"}
<body class="{if segment_1 == ''}home{if:else}{segment_1}{/if}">
<div id="page" class="container">
<div class="span-22 prepend-1 append-1 last">
{embed="shared/masthead"}
{if logo !=''}
<div class="news_item_logo">
{organization}
{if link}<img src="{logo}" width="130" alt="{title}" />{if:else}
<img src="{logo}" width="130" alt="{title}" />{/if}
{/organization}
</div><!-- /.news_item_logo -->
<ul>
<li><h3>{title}</h3></li>
<li>{pub_date}</li>
{organization}
<li>{if link}{/if}{exp:php_text_format type="lowercase"}{if url_text != ''}{url_text}{if:else}{name}{/if}{if link}{/exp:php_text_format}{/if}</li>
{/organization}
<li>{if file}PDF{/if}{if web_link !='' AND file !=''} | {/if}{if web_link}HTML{/if}</li>
</ul>
{if:else}
<ul class="no_logo">
<li><h3>{title}</h3></li>
My question is this, I see curly brackets {} around if statements and i want to know first what language it is and second is there a way to debug like php print_r() because the code always goes to the else with the no_logo class and i want to know what and how i can test these variables "segment1" and "logo" and "organization" and "url" How do and where do i inspect these variables
You can gain some info about the given variables and values in the template using the following within your index.php:
<?php
$EE = get_instance();
var_dump($this->EE->TMPL);
?>
Note that PHP must be enabled in templates for that to work (see PHP in Templates).
{embed="shared/head"} - include the template head from the template group shared
<body class="{if segment_1 == ''}home{if:else}{segment_1}{/if}">
if the URI segment (EE/CI works with segments eg site.com/segment1/segment2/xxx) is empty (you are on the home page (www.site.com), then add no body class.
else, the user is on a page (in EE this is a template group), so set the class to be the name of the template group.
site.com/about-us produces class="about-us" - handy for page specific styling.
{embed="shared/masthead"} - include masthead
and so on.
The rest are conditionals to check if the variables have values, and outputs them
I presume you're using EE2.0, I'm not sure what {organizaton} is specifically, but that style:
{organization} {foo} {/organization}
in code igniter at least, is generally the equivalent of a foreach or looping through a recordset:
foreach($organizations as $organization) { // do something }
This is written in Expression Engine's own templating language.
You would have to check the documentation to see whether there is any way to debug variables.
Possibly helpful links:
Quick Reference Chart
PHP in Templates