I'd like to internationalize the strings of my view.yml, I can't find how to do this.
I have a solution that is bad, in my opinion:
metas:
title: <?php echo sfContext::getInstance()->getI18n()->__('TITLE'); ?>
I'd like to find a way to do it without calling "sfConfig::getInstance()". Is it possible?
Never ever use sfContext for I18n in Configuration-Files! In such a case use the setTitle function in the View (not the controller)
<?php $sf_response->setTitle(__('TITLE'));?>
Since include_title() does not translate what it finds in view.yml, I made this very simple function in my custom helper:
function include_translated_title($context)
{
$title = $context->getI18N()->__($context->getResponse()->getTitle());
echo content_tag('title', $title)."\n";
}
Then I use it in my layout.php files:
<head>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_translated_title($sf_context) ?>
This way, I can use translation keys in my view.yml
You can do this in your action instead:
$this->getResponse()->setTitle(sfContext::getInstance()->getI18n()->__('TITLE'));
I dont think there's a way around using sfContext. You might be able to do something like this by getting rid of the default <?php include_title() ?> in your layout/view and the using the template i18n format to internationalise it:
<title><?php echo __('TITLE') ?></title>
Related
Is there any way I could strip html out of this?
<?php echo $this->form->renderField('monday'); ?>
In the back end theres a selection where you pick options that show up in a schedule but they are showing up as html and I need them to show up as plain text for the selection.
you can use php strip_tags function
<?php echo strip_tags($this->form->renderField('monday')); ?>
http://php.net/manual/en/function.strip-tags.php.
If you wanna keep some tags, look at the section allowable_tags
You should know that select and option are also html tags and will be removed if you use strip_tags. So you can allow those tags. You can modify your code like this
<?php $field = strip_tags(($this->form->renderField('monday')),'<select><option>');
echo $field;
?>
I have used something like that-
<?php if(current_url() == site_url()): ?>
...
...
<?php endif; ?>
But it's not working. I think there's something that I missed.
If you simply want to check if you're on the homepage of your site try this:
<?php if(strcmp(uri_string(),'')==0) : ?>
We are on the home page.
<?php endif; ?>
This solution will still work regardless of whether the base url is set correctly or not, unlike comparing base_url() and current_url().
Ensure that you have loaded the url helper either in your constructor or via autoloading.
I want to pass some arguments from a view to the cportlet widgets called by this view, but it seems doesn't work when I do it like this:
<?php
$this->beginWidget('zii.widgets.CPortlet');
$this->widget('ProductsBrowser',
array('params'=>$params));
$this->endWidget(); ?>
How can I accomplish it succesfully? Please help me! Thanks!!
Do You read documentation?
http://www.yiiframework.com/doc/guide/1.1/en/extension.use#widget this just should work.
The Correct way is as shown
<?php $this->beginWidget('zii.widgets.CPortlet', array(
'params'=>$params)); ?>
//body content
<?php $this->endWidget(); ?>
I know that you can call a cms block directly from a template file using the following:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>
Is there some way to do this with widget instances?
In your template:
<?php
$filter = Mage::getModel('widget/template_filter');
echo $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
?>
Andrew missed toHtml() function at the end:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2)->toHtml(); ?>
To know the correct parameters "type", "template" and more, you can use the "Insert widget" button on the graphical editor in a block/page template, then you click the show/hide editor and you get the code
The answer above may work, but the same thing can be achieved by loading the widget as you would a static block and passing in the custom parameters using the magic setters like this:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2); ?>
I see something like:
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
and this
<?php if(!$_product->isGrouped()): ?>
But couldn't find a way to target only the Simple Product type in similar manner.
<?php if( $_product->getTypeId() == 'simple' ): ?>
As an alternative possibility you could assume a Simple product is on that is no other type.
<?php if (!$_item->isComposite() && !$_item->isSuper() && !$_item->isVirtual()): ?>
<!-- Simple type only -->
<?php endif; ?>
There is already a template file catalog/product/view/type/simple.phtml that only displays for Simple type products.
If that doesn't show in the right place for you look in layout/catalog.xml for <PRODUCT_TYPE_simple> to see how to make your own Simple-only template file.