I have an url like $article.url|ezurl(,'full'), but I need to pass additional parameters to it (eg. (offset)/2).
Please note that I am using attribute_view_gui for images, so I can't just hardcode it.
I tried creating variables:
{def $url = $article.url|ezurl(,'full')}
And then adding values there, but it's useless.
What can I do?
You can add view parameters to the URL before passing it to the ezurl() template operator.
<a href={concat( $article.url, '/(offset)/2' )|ezurl}>{$article.name|wash}</a>
Note that ezurl adds double quotes by default so you don't need to add them in your html/tpl code with <a href="{concat...}">...
If you want to use a $url variable, then you need to tell ezurl not to add these quotes :
{def $url = concat( $article.url, '/(offset)/2' )|ezurl('no')
$name = $article.name}
{$name|wash}
You can also use the "owviewparams" extension to modify, add or remove view parameters from an url : http://projects.ez.no/owviewparams
Related
How use same url for different rutes expression in codeigniter.
For exemple, to use "x" like any word in my code and always to result in same url?
$route['list'] ='x/list';
Url expected: mysite.com/list
You have to set a value for x as $x = "http://www.example.com"; then use it like this $route['list'] ='$x/list'; but you may need to revise the $route[''] variable name list, view example on https://www.javatpoint.com/codeigniter-url-routing
One simple thing:
I want to combine the {s name="*"} and {link file="*"} blocks.
src="{link file='{s name='sFooterPaymentsIcon'}{/s}'}"
The problems should be the
'
signs.
How can I do that?
You can try assign a new variable and pass that on file parameter, like:
{assign var="my_file" value="{s name='sFooterPaymentsIcon'}{/s}"}
and then
src="{link file="$my_file"}"
You can do it this way:
//Assign snippet value to variable $snippetLink, in case variable is empty - assign LinkInCaseSnippetEmpty
{assign var='snippetLink' value='LinkInCaseSnippetEmpty'|snippet:'TheNameOfSnippet':"Namespace/If/Need"}
//assign source from variable $snippetLink
src="{link file=$my_file}"
In one line:
src="{link file='LinkInCaseSnippetEmpty'|snippet:'TheNameOfSnippet':'Namespace/If/Need'}"
{s} is for for text-snippets and should not be used for configuration-variables. If you need to make an include configurable, you should create a plugin for that.
The plugin should have a frontend-subscriber and make the file-include configurable via backend configuration-form. In the subscriber you can pass the configuration-value for the file-include to the frontend-view.
how to write url address with parameter like this
www.example.com/param1/var1/param2/var2
and next get it with :
$param1 = Mage::app()->getRequest()->getParam('param1');
$param2 = Mage::app()->getRequest()->getParam('param2');
The default router expects that the first 3 parts in the url to be module, controller, action and then the rest of the parameters are treated as GET parameters.
You can generates such an url like this:
Mage::getUrl('module/controller/action', array('param1'=>'var1', 'param2'=>'var2'))
check here for full deails on this :
you need to do something like this.
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters
Mage::getUrl('cms/page/view', array('id' => 1));
// http://www.example.com/cms/page/view/id/1
Also your code to get these values from url is correct.
Is there a Magento function to get the value of "id" from this url:
http://example.com/path/action/id/123
I know I can split the url on "/" to get the value, but I'd prefer a single function.
This doesn't work:
$id = $this->getRequest()->getParam('id');
It only works if I use http://example.com/path/action?id=123
Magento's default routing algorithm uses three part URLs.
http://example.com/front-name/controller-name/action-method
So when you call
http://example.com/path/action/id/123
The word path is your front name, action is your controller name, and id is your action method. After these three methods, you can use getParam to grab a key/value pair
http://example.com/path/action/id/foo/123
//in a controller
var_dump($this->getRequest()->getParam('foo'));
You may also use the getParams method to grab an array of parameters
$this->getRequest()->getParams()
If your url is the following structure: http://yoursiteurl.com/index.php/admin/sales_order_invoice/save/order_id/1795/key/b62f67bcaa908cdf54f0d4260d4fa847/
then use:
echo $this->getRequest()->getParam('order_id'); // output is 1795
If you want to get All Url Value or Parameter value than use below code.
var_dump($this->getRequest()->getParams());
If your url is like this: http://magentoo.blogspot.com/magentooo/userId=21
then use this to get the value of url
echo $_GET['userId'];
If you want more info about this click here.
If it's a Magento module, you can use the Varien Object getter. If it's for your own module controller, you may want to use the register method.
Source: http://www.vjtemplates.com/blog/magento/register-and-registry
Magento can add a suffix that is defined by the user to append onto urls. I want to get that suffix from my code. Does anyone know an easy way to do this?
If it's stored in the configuration area, then you access it just as you would any other configuration value, by using Mage::getStoreConfig($config_path) where $config_path is defined in the system.xml of the module that defines it.
If you're not sure of the $config_path, then I usually cheat and inspect the textbox/dropdown in the configuration section, take a look at the id, e.g. dev_log_file, and translate it to dev/log/file. You'll need to use some intelligence when there are multiple _ though :)
Nick's answer is good but the actual answer to this question is:
$suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
If I am not mistaken, here is the code ( because I don't understand what you want with URL )
<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
$url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
echo $url_parts[0]; //check here
?>
complete product url:
$productId = ***;
$productUrl = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();