zend framework 2 get locale from view PhpRenderer - internationalization

How I can obtain traslator locale in my view?
I want to do it starting from the variable $this (the PhpRenderer of the view).
i.e. I don't want use onBootstrap nor ActionController because I don't care to have a view variables.
Thank you!

You should try:
<?php echo \Locale::getDefault(); ?>
Many of the I18n classes make reference to PHP's Locale class (http://www.php.net/locale) - so in my opinion that would be a good starting point.

<?php echo $this->plugin('translate')->getTranslator()->getLocale(); ?>
See:
Get local value in layout or view in Zend Framework 2

Related

Processwire Add css class to page

I there a possibility to add a classname to a page?
I can't figure out how to implement such feature or if it already exists.
I'm using Processwire 3.0.42.
Put something like this in your template where the body is:
<body class="<?php echo $page->template->name; ?>">
That will give your page body tag a class equal to page template name.
You can add a page title in the same way.
<body class="<?php echo $page->name; ?>">
Don't be worried about adding a class to every page. The overhead of doing this is negligible.
If you wish to add a different class you would need to add a field to your template and append it to the code above.
As always in ProcessWire, everything is under your control. Alternatives to #ivangretsky's perfectly good answer would include-
Simply include a conditional in your template file. (This doesn't scale well if you need to add other classes to other pages using the same template.)
<?php
$bodyClass = '';
if($page->id == 1021) $bodyClass = 'my-class';
?>
<body class="<?php echo $bodyClass; ?>">
NB Using $page->id is better than $page->name, for example, as the ID doesn't change while the name could.
You could also add a field to the page template definition. Add a field called something like 'Body Class'. Then use the content of that field in your template file.
<body class="<?php echo $page->body-class; ?>">
This will scale better than my other suggestion, and there are options in the ProcessWire backend to hide or partially hide the field during normal use if you don't want users messing with its value.
One 'gotcha' from the CSS spec to be aware of is that CSS identifiers, including class names and IDs cannot start with a digit, so you cannot just use $page->id.
There are lot of options and it depends on your needs and maybe imagination :-).
You can use page name, template name, page id, or maybe combination.
<body class="<?php echo $page->template->name; ?> page-id-<?php echo $page->id; ?>">
// Output
<body class="your-template-name page-id-1234">
This way you can target template, page, or both.
Or, as mentioned by #ivangretsky, you can add custom field to page. And again, you can combine this aproach with template name, etc.
It depends on your needs and what you want to achieve.
Notice:
Using $page->id is better than $page->name, as the ID doesn't change while the name could. #DaveP

add a CSS className to the custom option fields like radiobox and select

I want to group and show in different popup product custom options on frontend on product view page. So I want to give specific class to every product option from backend.
refernce from here
I have use this code but this is giving custom class options only for text-box type options, I want custom class to all type of product options.
Can anyone help?
Thank you.
Something I've used before (although I admit, does not look like a very neat way of doing it) is this in the catalog/product/view/options.phtml:
$search = 'product-custom-option';
$replace = 'product-custom-option form-control';
<?php foreach($_options as $_option): ?>
<?php echo str_replace($search, $replace, $this->getOptionHtml($_option)); ?>
<?php endforeach; ?>
Where the css class 'form-control' was the one I wanted to add.
[EDIT]
In that case, one solution I can think of is this:
Create a system.xml where you can add the CSS classes for the various option types
Create a helper class for retrieving the saved CSS classes
Edit the catalog/product/view/options/type/*.phtml files in your theme where you add the CSS classes by using the helper.
Would that work for you?

codeigniter dynamic data template

I have this template view at view/include
<?php $this->load->view('include/header'); ?>
<?php $this->load->view($sidebar_column); ?>
<?php $this->load->view($result_column); ?>
<?php $this->load->view($footer_row); ?>
<?php $this->load->view('include/footer'); ?>
and i have the footer_row html at view/include
<div> this is footer row <?php echo $username ?></div>
then i call the footer_row in my controller
$data['footer_row'] = 'include/footer_row';
$this->load->view('include/template',$data);
My question, the footer_row is logged in user info and it appear in EVERY pages. With the above method I use, I have to call and retrieve the user info in every controller. How can i make it reusable so i don't need to repeat myself.
Reusability comes from making use of your constructors, and parent classes. Have a look at my previous answers:
Header and Footer in CodeIgniter
Constructor session validation for different functions
Instead of using this method why dont you use a template library which is easy to use. I would recommend Philsturgeons Template Library but there are some more you can use any that fits to your requirements.
Williams Concepts
http://williamsconcepts.com/ci/codeigniter/libraries/template/
Phil Sturgeons's
http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/
Most Simple
http://maestric.com/doc/php/codeigniter_template
And Finally Binpresses's
http://www.binpress.com/app/codeigniter-template-library/223

Codeigniter URL for navigation

I can't figure out how to do the url links.
Basically I have my navigation bar, and I don't know which CodeIgniter URL code to use and how to implement it.
Is what I'm doing here right?:
<?php $this->load->helper('url'); ?>
<li>About Us</li>
I tried to do an anchor like this, but when I load the page it just turns up blank:
<?php echo anchor('views/about.html', 'About Us', title='About Us'); ?>
What am I doing wrong?
There are two ways to make links:
CodeIgniter helper style:
<?php echo anchor('about', 'About us', 'title="About us link"'); ?>
More common HTML with URL echo:
About us
Both will output:
About us
Though if I understand what you are trying to achieve, your mistake is elsewhere.
You don't include the views part, as your URL should point to the controller, not a view. The only case is if you have a controller named views.
CodeIgniter is set up so that it doesn't include file extensions like .html in URL's by default. It does if you've set them up in your config file in $config['url_suffix'] = '';, which is null by default.
See if you've made any of these mistakes.
That is another way on how you do the URL if you are using the URL helper in CI. You should try this, make the base_url() as the value for href. Try this,
About Us
You have to try like this
About Us
or you can give like
About Us
and in the "about" function you put
$this->load->view('about');
but i think the firstone will works for you fine.

Magento title not showing on category view

On http://www.justdoors.co/vinyl-colours.html for whatever reason the product titles aren't showing.
This is the relevent code from our template/catalog/product/list.phtml file:
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
It was working OK in magento 1.5.1 but we've done an update to 1.6.0 and seems to be since that. can anyone shed some light on this problem, I don't seem to be getting and error message so not really sure where to start!
Seems like your variable is just empty. Always look what is inside of your object by dumping it or inspecting it with debugger
<?php print_r($_product);?>
or if its too large and has many references then try to see object parameters only
<?php print_r(array_keys($_product));?>
Then you can inspect yourself what variables you can ask directly from object or what you need to query or extend your collections to get by default.
Its worth to look if your product name attribute is enabled for listings (from attribute settings).

Resources