How to get Joomla template style name? - templates

I have a joomla template that has two styles. The name of the template is default, and the styles are cats and arts. is there a way to return the name of the current style in use.
the code below only return the name of the template
$template = $app->getTemplate();
if I do an echo $template; I get default. But what I would like to get, is whether I am using the style cats or the style arts
Thank you

The template object doesn't contain the name of the a templates style variations (as it's only really used for human administrators as a mnemonic).
The only way to tell which "style" is being used is to look at the id value of the template… this value will correspond to the one you see in the ID column of the "Template Manager - Styles" view.
// Get the Joomla Application
$app = JFactory::getApplication();
// Get the template
$template = $app->getTemplate(true);
// Echo the ID
echo $template->id;
If you really need the "name" I think you're probably making a design mistake, having said that you could try loading the style model for the $template->id and retrieving it that way. e.g. something like this (warning typed directly into SO, NOT TESTED!)
// Initialise some vars
$name = 'Style';
$prefix = 'TemplatesModel';
$config = array();
// Get the model
$templateStyleModel = JModelLegacy::getInstance($name, $prefix, $config);
// Load the specific style instance.
$templateStyleModel->load($template->id);
// Echo out the style name
echo $templateStyleModel->title;

$params = $app->getTemplate(true)->params;
Use $params->get() to get the particular style's params.

The solution look are looking for is:
$app = Factory::getApplication();
$template = $app->getTemplate(true);
$styleModel = new Joomla\Component\Templates\Administrator\Model\StyleModel();
$style = $styleModel->getItem($template->id);
$style->alias = Joomla\CMS\Filter\OutputFilter::stringURLSafe($style->title);

Related

XCART-5 Get Attributes Values in programming and Assigning some other values progmatically

I am working on Xcart-5 website customization. And I created my own module and doing work on that. I just created some Global Attributes (" As a Plain text ") field and assign these attributes to some product. Now I want to access these fields value in programming in the product details page for assigning some other value programatically at run time.
How can I achieve this task. Kindly provide me the solution .
In your module you should decorate the \XLite\Model\Attribute class and extend the getAttributeValue() method there.
For instance, if I use a module with developer ID Tony and module ID AttributesDemo, then I would need to create the XCartDirectory/classes/XLite/Module/Tony/AttributesDemo/Model/Attribute.php file with the following content:
<?php
// vim: set ts=4 sw=4 sts=4 et:
namespace XLite\Module\Tony\AttributesDemo\Model;
/**
* Attribute
* #MappedSuperClass
*/
abstract class Attribute extends \XLite\Model\AttributeAbstract implements \XLite\Base\IDecorator
{
public function getAttributeValue(\XLite\Model\Product $product, $asString = false)
{
$result = parent::getAttributeValue($product, $asString);
if (!$asString) {
foreach ($result as $obj) {
if ($obj->asString() == 'Mac') {
$obj->getAttributeOption()->setName('Windows');
}
}
}
return $result;
}
}
Such implementation will change Mac values to Windows ones in all attributes.

Getting the Tag name of a element crawled with DomCrawler in PHP

I am crawling my html view with PHPUnit, using DomCrawler
$element = $crawler->filter("#myElement");
Once I have the element, how could I know the kind of tag that it is? (<input>, <select>, ...)
I know I could do this:
$element = $crawler->filter("input#myElement");
but I need to extract the name of the tag, and store it in a variable
As far as I can tell it, this should work:
$element = $crawler->filter("#myElement");
$name = $element->getNode(0)->tagName;
The Crawler::getNode(index) returns a DOMElement that has the tagName read only field.
Update: nowadays it is
$element = $crawler->filter("#myElement");
$name = $element->nodeName();
... which is actually a wrapper for
$crawler->getNode(0)->nodeName

How to update module parameters in J2.5?

i am trying to update the value of parameter . I have a hidden field in xml file, i need to update its value , value is dynamic.
I got the parameters using
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('mod_name');
I want to avoid the use database query method .
Is there joomla predefined function to achieve this task?
thanks in advance
-Neil
Unfortunately Joomla doesn't have an in-built API feature to set a parameter without using a database query. Try the following:
<?php
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'mod_name'); // change module name here
$params = new JRegistry();
$params->loadString($module->params);
$params->set('param_name', 'value'); // change parameter name and the value
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update('#__extensions AS a')
->set('a.params = ' . $db->quote((string)$params))
->where('a.element = "mod_name"'); //change module name here
$db->setQuery($query);
$db->query();
?>
I have tested this code so let me know if it works

Opencart how to add everything from the language file in php loop

It there a way to read everything from within a language with Opencart?
At the moment I have to:
Controller
$this->load->language('help');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['tab1'] = $this->language->get('tab1');
Language File
<?php
// Heading
$_['heading_title'] = 'Help';
$_['tab1'] = 'Account';
?>
The easiest thing to do is to use array merge at the top of your controller
$this->data = array_merge($this->data, $this->language->load('language/file'));
or simply
$this->data += $this->language->load('language/file');
Edit
For 2.x, use
$data = array_merge($this->data, $this->language->load('language/file'));
3.x does this automatically
In system/library/language.php is a
function to get everything called all().
This is how to get a single item:
$var = $this->language->get('heading_title');
This returns an array with all language entries:
$var = $this->language->all();

Show Joomla module only in specific articles?

Is it possible to show modules in Joomla only in a specific article (not per menu item), but in standard module position?
For example somehow get the current article id in a template and insert the modules with according id suffix in the name?
I would advise you not to hardcode things like this in the template. My question is, why don't you want to use a menu item? You can create a hidden menu item for that article and use it, then assign the module to that menu item.
If you still want to do it without using a menu item, a possible workaround would be to use something like "mod_php" (some module that allows you to use php code) and do something more or less like this:
Create the module and assign it to a position that is not used anywhere (you can type whatever you want in the module position)
In your php module, put this code:
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
if ( $option == "com_content" && $view == "article" && $id == YOUR_ARTICLE_ID ) {
$module = JModuleHelper::getModule('your_module_type', 'module_title');
if ( ! empty( $module ) ) {
$attribs = array( 'style' => 'xhtml' );
echo JModuleHelper::renderModule( $module, $attribs );
}
}
I'm sorry if the code snippet is not showing properly, but I hope you can read it ok. Just one thing, when you fill in the part saying 'your_module_type', don't include the "mod_" part of the name. For example, if you want to output a module of type "mod_article_list", you should write "article_list" in "your_module_type".
I hope it helps!