In the secondary development of magento, we often use functions in magento to obtain various URLs. For the convenience of magento program upgrade without having to recreate the module, we can directly write PHP code in magento block.
Below are some common functions for getting urls: Get the code of various URLs in magento block.
Obtain the URL with HTTP in the Media Directory: Mage: getbaseurl ('media ')
Similarly, you can obtain the address of the skin and JS directories: Mage: getbaseurl ('skin'), Mage: getbaseurl ('js ')
Get the homepage URL: Mage: getbaseurl ('web ')
Get the URL of the specific page in the block: $ this-> geturl ('catalogsearch/advanced/result'). Here is the URL of the advanced search result page.
Get the image URL directly: $ this-> getskinurl ('/images/logo.jpg ')
The code for directly calling the URL in the magento background CMS (content) is as follows:
Go to homepage: {store direct_url = "home "}}
Introduce an image on the page: {skin url = 'images/Media/main_page_banner.jpg '}}
**************************************** *********************
Let's talk about something else !!!!
1. In the phtml page, that is, in the template file,
Call in phtml
Yes <? PHP echo $ this-> getskinurl ('images/image')?>
Or in XML,
<Reference name = "right">
<Block type = "catalog/product_compare_sidebar" before = "cart_sidebar" name = "catalog. Compare. Sidebar" template = "catalog/product/compare/sidebar. phtml"/>
<Block type = "Core/template" name = "right. Permanent. callout" template = "callouts/right_col.phtml">
<Action method = "setimgsrc"> <SRC> images/image name </src> </Action>
<Action method = "setimgalt" translate = "Alt" module = "catalog"> <alt> keep your eyes open for our special back to school items and save a lot! </ALT> </Action>
</Block>
</Reference>
Here we have set the corresponding template file, the location where the template file appears, and the image path. You can use
<? PHP echo $ this-> getskinurl ($ this-> getimgsrc ()?> To obtain the image path. Of course, this setting is very troublesome. Generally, if you call an image directly, we can simply use the previous method, which is clear, but sometimes we need to place it on the left and right sides, in this way, we usually create a new template file first, and then catalog. declare the block in the XML file (slightly modify the content above), and then you can call it to change the image.
2. Call the image in the CMS block set in the background. We can use the following code to call
A href = "<? PHP echo $ this-> getbaseurl ()?> "> <Span> homepage </span> </a> </LI>
<? PHP echo $ _ menu;?>
3. geturl ()
Action = "<? PHP echo Mage: geturl ('counter')?>" Equivalent to action = "<? PHP echo Mage: geturl ('counter/index/Index')?>"