PHP:
<snippet>
<content><![CDATA[
foreach (\$${1} as \$${2:k}=>\$${3:v}) {
${4}
}
]]></content>
<tabTrigger>fore</tabTrigger>
<scope>source.php</scope>
</snippet>
HTML (and on .php files with html)
<snippet>
<content><![CDATA[
<?php foreach (\$${1} as \$${2:k}=>\$${3:v}) : ?>
${4}
<?php endforeach; ?>
</script>
]]></content>
<tabTrigger>fore</tabTrigger>
<scope>source.html, text.html.basic</scope>
</snippet>
how can I enable "text.html.basic" on the second snippet without making it trigger when I'm on a PHP file, since it's also "text.html.basic source.php.%"
Note: you have an excess (as I persume) </script> ending tag in HTML snippet.
What you have to do is this:
HTML
<snippet>
<content><![CDATA[
<?php foreach (\$${1} as \$${2:k}=>\$${3:v}) : ?>
${4}
<?php endforeach; ?>
]]></content>
<tabTrigger>fore</tabTrigger>
<scope>text.html - source.php</scope>
</snippet>
PHP
<snippet>
<content><![CDATA[
foreach (\$${1} as \$${2:k}=>\$${3:v}) {
${4}
}
]]></content>
<tabTrigger>fore</tabTrigger>
<scope>source.php</scope>
</snippet>
As you may see, the HTML snippet negates the source.php scope with a - (minus) sign
Related
Hy ! I'm trying to display the categories on a cms page.I've tried all the solution on the web but none is working for me. The last one i've tried is this.
1.I've added this code in content tab of my cms page :
{{block type="catalog/navigation" template="catalog/category/list.phtml"}}
2.I've created the list.phtml and put the file on app/design/theme-name/template/catalog/category.
Here is the code pf my file
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $open = $this->isCategoryActive($_category); ?>
<?php
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if ($immagine = $this->getCurrentCategory()->getImageUrl()):
?>
<div class="catalog-image">
<div>
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="313" height="151" />
</a>
</div>
<div class="left"><h2><?php echo $_category->getName()?></h2></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
What I'm doing wrong ? Thanks !
Add this code in content tab of your cms page:
{{block type="core/template" template="page/categories-list.phtml"}}
Create a file in the theme such "categories-list.phtml"
path: app/design/theme-name/template/page/categories-list.phtml
In this file, write the following code in order to get a collection of all the categories:
<?php
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
?>
If you want only some categories of parent, use the following code:
<?php
$parent_category_id = 5; // this is ID of parent category
$categories = Mage::getModel('catalog/category')->getCategories($parent_category_id);
?>
To display categories on the screen, use loop, look below:
<?php foreach ($categories as $category): ?>
<p><?php echo $category->getImageUrl(); ?></p>
<p><?php echo $category->getName(); ?></p>
<?php endforeach; ?>
If you use the categories of the parent category to display the image, use the following code:
Mage::getModel('catalog/category')->load($category->getId())->getImageUrl();
Create a folder under catalog with name navigation and put your list.phtml file there it will work.
{{block type="core/template" template="catalog/navigation/list.phtml" category_id="507" }}
Category Display Mode shuould be in static block in display setting.
Not sure on the best way to go around this and am looking for solutions. I have the requirement to create a blank page (that I will later add code to) with a specific theme as the design. I've created the custom theme at: /app/design/frontend/indigo/mytheme/ and need to know how to create a page lets call it /test.php that has the theme applied to it.
Code so far is this, but this only shows the default theme:
<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');
echo $headBlock->toHtml() . $headerBlock->toHtml();
?>
My content goes here
<?php
echo $footerBlock->toHtml();
?>
The solution is quite basic, you just need to set the store ID:
Mage::app()->setCurrentStore(STORE_ID);
So the final code looks like this:
<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('STORE_ID', 15);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Mage::app()->setCurrentStore(STORE_ID);
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $layout->getBlock('head')->toHtml() ?>
</head>
<body>
<?php echo $layout->getBlock('after_body_start')->toHtml() ?>
<?php echo $layout->getBlock('global_notices')->toHtml() ?>
<?php echo $layout->getBlock('header')->toHtml() ?>
<div class="content-wrapper">
<div class="container_12">
<?php echo $layout->getBlock('breadcrumbs')->toHtml() ?>
<div class="main-container col1-layout">
<div class="grid_12 col-main">
<?php echo $layout->getBlock('global_messages')->toHtml() ?>
<?php echo $layout->getBlock('content')->toHtml() ?>
My content goes here
</div>
<div class="clear"></div>
</div>
</div>
</div>
<?php echo $layout->getBlock('footer')->toHtml() ?>
</body>
</html>
I think there are cleaner solutions you could take out of these: https://magento.stackexchange.com/questions/154974/create-completely-empty-page-in-magento-1-9-2-4 depending on how close to core you want to be :)
EDIT - A Clean complete solution:
Create a new custom controller (https://www.pierrefay.com/magento-training/create-a-controller-tutorial.html)
class Vendor_Module_LoremController extends Mage_Core_Controller_Front_Action
{
/**
* Get a shop now block for specific product
*/
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
// Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); // If you need to debug to see which layout handles are available
}
}
In your themes local.xml ( /app/design/frontend/[vendor]/[theme]/layout/local.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<vendor_module_lorem_index>
<remove name="header" />
<remove name="footer" />
</vendor_module_lorem_index>
</layout>
Is there anyone who can help me?
I am making a website using magento, but I am really struggeling on creating custom product tabs.
I tried using a couple of extensions such as Easy tabs and couldn't get it working.
I also tried following this http://www.joomlart.com/documentation/magento-faqs/magento-add-custom-tabs-to-product tutorial but didn't have any luck because some of the code was missing in my view.phtml.
Is there anybody who can give me a detailed explanation on this topic?
That is a complicated way to this.
First you need to create or update your local.xml file IF you do not have a local.xml file you can create one in
app->frontend->[Package Name]->[Theme Name]->layout->local.xml
Once this is created you can copy exactly what I have in this post into that file for a start of how to use one.
DO ALL UPDATES THROUGH A LOCAL.XML file not through page.xml catalog.xml, checkout.xml etc!! This will make upgrades significantly easier later down the road. Additionally, you will be able to quickly see all changes you have made to your site in one file.
Within your local.xml file
I commented what you have to do within the code / hopefully this makes it easier to understand what you are doing.
<?xml version="1.0"?>
<layout version="0.1.0">
<!-- Product Detail Page -->
<catalog_product_view translate="label">
<!-- Add Tabs -->
<reference name="product.info">
<!-- Both files that need to be created their contents are referenced below -->
<!-- Create a file named attributes.phtml in /YourPackage/Yourtheme/template/catalog/product/view/tabs.phtml -->
<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
<!-- Create a file named attributes.phtml in /YourPackage/Yourtheme/template/catalog/product/view/attributes.phtml -->
<action method="addTab" translate="title" module="catalog"><alias>additional</alias><title>Specifications</title><block>catalog/product_view_attributes</block><template>catalog/product/view/attributes.phtml</template></action>
</block>
</reference>
</catalog_product_view>
</layout>
<!-- End of Local.xml -->
<!-- Contents of tabs.phtml -->
<ul class="product-tabs">
<?php foreach ($this->getTabs() as $_index => $_tab): ?>
<?php if($this->getChildHtml($_tab['alias'])): ?>
<li id="product_tabs_<?php echo $_tab['alias'] ?>" class="<?php echo !$_index?' active first':(($_index==count($this->getTabs())-1)?' last':'')?>"><?php echo $_tab['title']?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php foreach ($this->getTabs() as $_index => $_tab): ?>
<?php if($this->getChildHtml($_tab['alias'])): ?>
<div class="product-tabs-content" id="product_tabs_<?php echo $_tab['alias'] ?>_contents"><?php echo $this->getChildHtml($_tab['alias']) ?></div>
<?php endif; ?>
<?php endforeach; ?>
<script type="text/javascript">
//<![CDATA[
Varien.Tabs = Class.create();
Varien.Tabs.prototype = {
initialize: function(selector) {
var self=this;
$$(selector+' a').each(this.initTab.bind(this));
},
initTab: function(el) {
el.href = 'javascript:void(0)';
if ($(el.parentNode).hasClassName('active')) {
this.showContent(el);
}
el.observe('click', this.showContent.bind(this, el));
},
showContent: function(a) {
var li = $(a.parentNode), ul = $(li.parentNode);
ul.select('li', 'ol').each(function(el){
var contents = $(el.id+'_contents');
if (el==li) {
el.addClassName('active');
contents.show();
} else {
el.removeClassName('active');
contents.hide();
}
});
},
remoteTabs: function(b) {
var controlledLink = $$("#"+b+" a")[0];
this.showContent(controlledLink);
}
}
var productTabs = new Varien.Tabs('.product-tabs');
//]]>
</script>
<!-- End of tabs.phtml -->
<!-- Contents of attributes.phtml / This will list of all attributes -->
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
<!-- End to attributes.phtml -->
<!-- alternative contents of attributes.phtml use this to only display one specific attribute -->
<!-- Replace InstructorBio with your attribute value -->
<!-- If your attribute code is product_tab then getInstructorBio would become getProductTab instructor_bio would be product_tab -->
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if ($_additional = $_product->getInstructorBio()): ?>
<?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getInstructorBio(), 'instructor_bio') ?>
<?php endif; ?>
Now for the final step: you have to call your tabs where you want them to display Because I used the "as" name as info_tabs this is the name you reference when you call in your view.phtml file
Insert this code inside your view.phtml and you will now have tabs
<?php echo $this->getChildHtml('info_tabs') ?>
I just create a module name referral. Now I want to place the referral block to another module template file name success.phtml. Can it be done?
referral.xml(in referral module)
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_success>
<reference name="checkout.success">
<block type="referral/referral" name="referralCallLink"><action method="referralCallLink"></action></block>
</reference>
</checkout_onepage_success>
<!--block type="referral/referral" name="referralAddSession"><action method="referralAddSession"></action></block-->
</layout>
success.phtml
<?php if($hasBoughtMCash): ?>
<div> Your
<?php echo implode(', ',$hasBoughtMCash); ?>
purchase is successful.
</div>
<?php endif; ?>
<h2>Share in Facebook and Earn for Free MCash!</h2>
<?php echo $this->getChildHtml(); ?>
Referral.php(block)
public function referralCallLink() //success page
{
...
$collection7 = Mage::getModel('referral/referrallink')->getCollection();
$collection7->addFieldToFilter('customer_id', array('eq' => $cust_id));
$collection7->addFieldToFilter('grouped', array('eq' => $grouped));
foreach($collection7 as $data3)
{
$product = $data3->getData('product');
$link = $data3->getData('link');
$imageurl = $data3->getData('url');
//facebook
$title=urlencode('Shop, Save and Get Rewarded at MRuncit.com');
$url=urlencode($link);
$summary=urlencode('I just bought '.$product.' from MRuncit.com and earned some MReward Points!');
$image=urlencode($imageurl);
?>
<p>
<a href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" target="_blank">
<img src="<?php echo $imageurl;?>" width="30">
I just bought <?php echo $product; ?> from MRuncit.com and earned some MReward Points!
</a>
</p>
<?php
}
}
Results
You should create the block as child of the success block in your layout XML:
<layout_handle_of_the_success_page>
<reference name="name_of_the_success_block_in_layout">
<block type="your/referral_block" />
</reference>
</layout_handle_of_the_success_page>
Then you can insert the following line in success.phtml:
<?php echo $this->getChildHtml('referral'); ?>
There are some names in the example XML that you have to replace with your own:
layout_handle_of_the_success_page - you will find it in the layout XML of the corresponding module. It should be in the form module_controller_action --> checkout_onepage_success
name_of_the_success_block_in_layout - also from the layout XML, look for the block with the success.phtml template and its name attribute --> checkout.success
your/referral_block - that's the class alias of the block that you want to insert in the form module/class --> referral/referral
I'm having trouble understanding how to place grocery_CRUD into a view.
My function in my control looks like this:
function folio()
{
$crud = new grocery_CRUD();
$crud->set_table('rfid');
$crud->columns('rfid','timestamp');
$data['output'] = $crud->render();
$data['title'] = 'Control Escolar - Folio';
$this->db->where('id', $this->uri->segment(3));
$data['query'] = $this->db->get('alumnos');
$this->load->view('folio_view', $data);
}
The code in my view file looks like this.
<?php foreach($query->result() as $row) { ?>
Datos Vitales - <B>Status:</b> <?=$row->status?><hr>
<B>Nombre:</b> <?=$row->nombre?> <B>Fecha de Nac:</B> <?=$row->fecha_nac?></br>
<B>Edad:</b> <?=$row->edad?> <B>Sexo:</B> <?=$row->sexo?> <B>Lugar de Nac:</B> <?=$row->lugar_nac?>
<B>Nacionalidad:</B> <?=$row->nacionalidad?><br><br>
Datos Escolar<hr>
<B>Folio:</b> <?=$row->folio?> <B>Grado:</b> <?=$row->grado?> <B>Grupo:</b> <?=$row->grupo?> <B>Turno:</b> <?=$row->turno?> <B>RFID:</b> <?=$row->rfid?><br><br>
Datos Generales<hr>
<B>Domicilio:</b> <?=$row->domicilio?> <B>Colonia:</b> <?=$row->colonia?> <B>Codigo Postal:</b> <?=$row->cpostal?></br>
<B>Telefono Particular:</b> <?=$row->telepart?> <B>Municipio:</b> <?=$row->municipio?></br>
<B>Telefono de Emergencia:</b> <?=$row->tele_emer?> <B>Tutor:</b> <?=$row->tutor?><br><br>
Datos Medicos<hr>
<B>Tipo de Sangre:</b> <?=$row->tipo_de_sangre?></br>
<B>Condiciones Conocidas:</b> <?=$row->condiciones?></br></br>
<hr>
<B>Entradas/Salidas Registradas:</b>
<?php echo $output; ?>
<?php } ?>
Which works well, however when I run it I get this where the CRUD should appear:
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: views/folio_view.php
Line Number: 65
What I'm trying to actually accomplish is for the CRUD to show the only the RFID entries matching the RFID field matching the student.
Actually the error describes exactly what is wrong there. So the problem is that you try to echo an object.
So imagine that your $output is an object like this:
stdClass Object
(
[output] => Your output will appear here....
[js_files] => Array
(
...
)
[css_files] => Array
(
...
)
)
So the solution to your problem is simply this:
echo $output->output;
Also consider that the only thing that grocery CRUD requires is to show somewhere the js_files and the css_files , so don't forget to have this in your template or view:
<?php foreach($output->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($output->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
If you want to be more "readable" to you can simply do this:
$data['gcrud'] = $crud->render();
And in your view/template to have something like this:
<?php foreach($gcrud->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($gcrud->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
...
<?php echo $gcrud->output; ?>
Lastly but not least, consider that the thing that you are trying to do will not work in the first place as I understood you want multiple CRUDs in one page:
<?php foreach($query->result() as $row) { ?>
...
<B>Entradas/Salidas Registradas:</b>
<?php echo $output->output; ?>
<?php } ?>
However you will realize that for the time being it will not work well for you as grocery CRUD doesn't support multiple CRUD forms in one page for the moment. So if you actually want to use grocery CRUD you have to change the logic that the view will show it