I want to get an array with all current template positions names as listed in the respective templateDetails.xml.
I tried:
$this->params->get('positions')
But it didn't work.
The code will be called or inserted into /templates/mytemplate/index.php file.
I've seen in the module parameters page a select that displays all available positions from all installed templates, maybe it gives a clue on how to achieve it.
Recently I edited a post in joomla docs here https://docs.joomla.org/JFactory/getXMLParser. Hardly 1 week back as it was not updated for a long time. You can get template position this way after giving templateDetails.xml location.
$xmlfile = 'templates/protostar/templateDetails.xml';//Change to your template
$xml = JFactory::getXML( $xmlfile );
//The position array is this `$xml->positions->position`
foreach ($xml->positions->position as $position) {
echo $position . "<br />";
}
Related
OK, so here is what I have and found (which works - however it produces a log Notice) "Only variables should be passed by reference in eval()" which is driving me absolutely crazy!
Initially like any theme region I added the regions I wanted for views use to the theme.info file.
; View Regions
regions[view_header] = View Header
regions[view_content] = View Content
regions[view_footer] = View Footer
In the views-view--page.tpl.php I placed these (where I wanted the region to render)
<?php print render(block_get_blocks_by_region('view_header')); ?>
<?php print render(block_get_blocks_by_region('view_content')); ?>
<?php print render(block_get_blocks_by_region('view_footer')); ?>
This produces a notice for each entry in the tpl yet it works as expected 100%
I then tried adding a hook in the themes template.php (in an attempt to make variables out of them) so I can just use <?php print $view_header; ?> like so:
function theme_preprocess_views_view(&$variables){
$variables['view_header'] = render(block_get_blocks_by_region('view_header'));
$variables['view_content'] = render(block_get_blocks_by_region('view_content'));
$variables['view_footer'] = render(block_get_blocks_by_region('view_footer'));
Again this works - and again this produces log notices.. this time 3 for each region on all page loads, so 9 instead of 3 (not just when the views-view--page.tpl.php loads) which traced back to theme template.php (same notice as listed above this time but no notice from the $variables used in the views template when that page loads).
Obviously I'm missing something here! Maybe this is entirely the wrong way to do this...
How do I make the theme regions usable variables in tpl's?
I'm under the impression everything I've found is years old (3 to 10) and likely worked fine for php 5.x - this site is currently using php 7.2.x (should that make a difference in how this needs to be done)
Any help here would be greatly appreciated, thank you!
This is because the function render() expects a reference, and only variables should be passed by reference :
function render(&$element) {
# code need to be able to modify $element
}
render('value'); # throws notice
render(block_get_blocks_by_region('view_header')); # throws notice
$value = 'value';
$build = block_get_blocks_by_region('view_header');
render($value); # Ok
render($build); # Ok
Also, I think the way to go should be to assign the renderable arrays to $variables in the preprocess hook :
function theme_preprocess_views_view(&$variables){
$variables['view_header'] = block_get_blocks_by_region('view_header');
$variables['view_content'] = block_get_blocks_by_region('view_content');
$variables['view_footer'] = block_get_blocks_by_region('view_footer');
# ...
}
... and let the template call render() :
<?php print render($view_header); ?>
<?php print render($view_content); ?>
<?php print render($view_footer); ?>
Here is a snippet of the xml I am working with:
My example xml
A client requested that we add the ability to filter which type of "news articles" are displayed on specific pages. They create these articles on another website, where they now have the ability to assign a one or more categories to each of the articles. We load the articles via php and xml.
The error I receive is:
Call to a member function getElementsByTagName() on null in ...
Here is the code from 2012 that I am working with:
$item = $dom_object->getElementsByTagName("Releases");
foreach( $item as $value )
{
$Release = $value->getElementsByTagName("Release");
foreach($Release as $ind_Release){
$Title = $ind_Release->getElementsByTagName("Title");
$PublishDateUtc = $ind_Release->getAttribute('PublishDateUtc');
$DetailUrl = $ind_Release->getAttribute('DetailUrl');
$parts = explode('/', $DetailUrl);
$last = end($parts);
I am trying to transverse to the category code and set a variable with:
$newsCategory = $ind_Release->getElementsByTagName("Categories")->item(0)->getElementsByTagName("Category")->item(0)->getElementsByTagName("Code")->item(0)->nodeValue;
This loads the current 2018 articles with the category slug being echoed, because they have an assigned category, but it fails to load 2017, 2016, and so on, I believe, because they are not assigned a category within the XML and this is breaking something.
A news article without a category appears with an empty categories node within XML
I understand that I am using getElementsByTagName, and because there is no element beyond the first categories node it breaks.
Is there a way to check that there is indeed a path to Categories->Category->Code[CDATA] before trying to set it as a variable and breaking it?
I apologize if this is confusing, I am not a PHP expert and could use all the help I can get. Is there a better way to transverse to the needed node?
Thanks.
You need to use XPath. If you're using DOMDocument, this is done via DOMXpath.
Your current approach uses chaining, and the problem with chaining is it breaks down if a particular juncture of it doesn't return what the following method relies on. Hence your error.
Instead, check the whole path from the start:
$domxp = new DOMXpath($dom_object);
$node = $domxp->query('/Categories[1]/Category[1]/Code[1]');
if (count($node)) {
//found - do something
}
In my PHP script, i want to check in any xml file, if any new item is published since my last checkout.
Currently, i use a foreach and a if, but i don't want to read all the xml file because i have a lot of file to check.
foreach($xml->channel->item as $item){
if (strtotime($item->pubDate) > $myTimestamp){
// new item
}
}
If possible, i want to use something like a while loop for ignore oldest item.
Thanks for helping a french man !
I have installed typo3, templavoila and mapped a template.
Everything works fine, except my content elements. They just don't appear. They did before I installed templavoila and mapped a template.
Also, when using
10 = RECORDS
10 {
tables = tt_content
source = 9
}
it does not give me any output.
even nothing with:
10 = RECORDS
10 {
tables = tt_content
source = 9
conf.tt_content = TEXT
conf.tt_content.value = TEST
}
Does anyone have a clue as to what I might be doing wrong?
You must include the css styled content static template in your TS template.
In your ts page object you need to assign it to the templavoila object.
# Default PAGE object:
page = PAGE
page.typeNum = 0
page.10 = USER
page.10.userFunc = tx_templavoila_pi1->main_page
Probably the page, where tt_content is situated is not visible to regular visitor ?
In this case, following snippet will help.
10 = RECORDS
10.tables = tt_content
10.source = 9
10.dontCheckPid = 1
Finally we got it to work. Don't know what I did wrong, but I guess I learned not to do it again.
I'll put the "solution" here since someone might find it helpful and lose more than a day over this like I did.
Solution:
copy an existing content element in list mode, pasted it on a page via page mode
This was to test if that would do anything. Guess what, everything worked again. Not only the newly copied element but also ALL other test elements created via different ways on different pages and storage folders.
Thank you all for helping and thinking along.
i'm using Joomla 1.6 + mysql
What I want to do at this point is to create dynamic links using content that exists on the database.
At this point i'm calling a function in php that creates an ordered list with the contents of a certain table, but right now I want that those items contain not only the text on the database but also a link associated with that item, so that i can display inside my joomla website the content on the database.
In other words I have 'N' itens that will be changed over time, and i need to display those 'N' items using an ordered list (this part is already working for 'N' items) and then each item contains a link to a joomla page/article/... dynamically generated in some sort of way in order to show contents on the database associated with that Item.
Please note that this has to work dynamically because content on the database will change over time and the number of links can contain 0 to N items.
Any ideas or pointers to do this?
Thank you
The best way to do this is to create a small content plugin.
function onPrepareContent( &$article, &$params, $limitstart ) {
$plugin =& JPluginHelper::getPlugin('content', 'myplugg');
$pluginParams = new JParameter( $plugin->params );
// get your data from the db
$rows = ...
// assemble the html for insertion
$content2insert = ...
// append the content into the joomla article
$article->text = $article->text . $content2insert;
return true;
}
Here is a full tutorial on content plugins:
http://docs.joomla.org/Creating_a_content_plugin