I was wondering, if there is any way to set mangeto language for specific area from Code?
What i mean is lets say i want a custom page to be in Spanish while other pages in my website in English.
Set cookie onChange event of custom drop in following manner
$cookie = Mage::getSingleton('core/cookie');
$cookie->set('selectedlang', 'spanish' ,time()+86400,'/');
and then make a if else statement
if($cookie->get('selectedlang')=='spanish')
//Show your spanish content
else
//Show your default content
Related
I have product with attribute address - where is product places. It is dropdown list. I want this atttribute will be a link on other site page with map and some other info about this address. But when i use html code in editor of attribute options it's not working. At the same time i checked property "Allow HTML Tags on Frontend" - it has "Yes" value. How can i do this?
Here is how my attribute looks like. and it seams to work:
For the attribute settings I just set to Yes Allow HTML Tags on Frontend and Visible on Product View Page on Front-end. The rest is set to No.
Here is how it looks like in the backend when editing a product.
And here is how looks in the frontend. And the link actually works.
I'm using CE-1.7.0.2.
Maybe the version is the problem. You can also try reindexing after you add the attribute.
[EDIT]
It seams that for 1.9 something changed.
See these lines in the attribute controller _filterPostData method:
foreach ($data['option']['value'] as $key => $values) {
$data['option']['value'][$key] = array_map(array($helperCatalog, 'stripTags'), $values);
}
You can view them here also: https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php#L167
The filter method looked differently in 1.8 and before: https://github.com/OpenMage/magento-mirror/blob/magento-1.8/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php#L153. It didn't have the strip tags on the options. Just the label.
I guess you can try to override the Mage_Adminhtml_Catalog_Product_AttributeController::_filterPostData method and make it look like it does in 1.8. But I don't know the risks.
While it's possible to manually enter the full title of a page displaying a category, how would I go about doing the same for an article page in Joomla 2.5?
The default is to use the article title as the page title, e.g. "How to care for goldfish", with an option to add the site name.
What I want is to have the title as follows:
How to care for goldfish | Fish care guides | FishSite.com
The obvious solution would be just to put all that in the title of the article, but then I'd have a problem in the "Latest articles" module, it would become unreadable with all the extra text.
How to solve this? Plugin, coding, or some clever solution? It needs to be more or less automatic though, I can access the Joomla database and change each page title manually but that wouldn't be feasible. If manual text entry is needed, it has to be in Joomla.
The plugin system responds to events, so the easiest solution would be a either a Content or System plugin that manipulates the Title by appending the relevant information prior to display.
I think with a content plugin you could use the onContentPrepare event to do all the work.
In rough psuedo code (i.e. this won't run), I would probably end up with something like this:
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
// Don't run this plugin when the content is being indexed
if ($context == 'com_finder.indexer') {
return true;
}
// Perform a sanity check to make sure we're on an article layout
// Build new title
}
By default parent::display($tpl); loads components/com_my_component/views/my_component/tmpl/default.php, but in some cases i need to load other php file which is in the same folder near default.php (for example components/com_my_component/views/my_component/tmpl/lol.php). How to do this from view.html.php.
P.S.
Tried load loadTemplate and setLayout methods with no luck.
Solved the problem by myself. Need to use the method setLayout and pay attention to the input syntax
$this->setLayout('dafault:lol');
parent::display($tpl);
By default, joomla looks for the layout keyword in the URL to decide which layout to display. If this variable is empty or not present then the tmpl/default.php layout will be loaded.
By editting your view.html.php file you can set the default layout by using the JView API, e.g. $this->setLayout('lol') will make the URL example.com/yourview equivalent to example.com/yourview?layout=lol.
However, this change alone will result in Joomla overriding it's default behaviour so that the layout request will be ignored. This means that the request example.com/yourview?layout=lmao will also display example.com/yourview = example.com/yourview?layout=lol
You can solve this easily by adding a condition around the setLayout function so that only if the layout keyword is not present then you will set the default layout to lol, e.g.
<?php
# ...
function display($tpl = null) {
# ...
# Edit : Set the default layout to 'lol'
$layout = JRequest::getWord('layout', '');
if (empty($layout)) $this->setLayout("lol");
// Display the view
parent::display($tpl);
}
# ...
I keep coming back to this and I've yet to find a satisfying solution.
What does work, from J1.5 right up to J3.4, for me has always been to set the $tpl variable in view.html.php
If $tpl is empty or "" then tmpl/default.php is displayed by default.
If you change $tpl to a string, e.g. $tpl="stacker" then it will look for and display tmpl/default_stacker.php
I've seen various differing theories on changing it earlier in the MVC so that it doesn't need the default_ pretext. e.g. tmpl/stacker.php
None have worked for me.
I'm working in mvc3 and did this thing to change the language by url address (it work great):
var urlString = window.location.host; //the url with localhost:XXX only -and if it changes it will adjust itself
var Lang = $(this)[0].value; //en or fr
window.location = "http://" + urlString + "/" + Lang;
but now I have a serious problem: window.location - refreshes the page, and the $(this)[0].value - returns to be as the beginning. for example if I change the combobox from "english" to "french", the language does change to french (coz the url isnt refreshed), but in the combobox, the selected field is "english" again and I cant change it because all the page is refreshed.
so...is anybody can tell me what to do??
thank in advance.
In your controller, I guess you're passing in the language as a parameter, set the selected value of your dropdown to the language passed in so that when the page is loaded the value is set and the correct item is selected.
If this is a refresh it is a complete reload of the page so you need to save state. Either investigate html 5's local storage (limited browser support)
http://www.w3schools.com/html5/html5_webstorage.asp
or when its selected save it in a preference cookie in javascript.
The code is already mostly written for you here - you'll just need to read it on page load and save it when the combo box changes.
Javascript remember combobox value
When using the MVC design pattern I usually try to make my view files as simple as possible.
Therefore in my View I try not to have lots of code like this:
if page title exists
display page title
else
display 'default page title'
end if
Instead, in my Controller I might use code like this:
if no page title is specified
page title = 'default page title'
end if
load the view (pass page title as a parameter)
Is this the best way to tackle this issue?
Keeping this if-else condition in the controller level is a better idea than moving into views. (if you can otherwise it's alright)
It will make your views look good !!!!