Magento News
Magento: load template file from admin module
Hi,
I’ve been following this tutorial on creating modules in the management section. I’m just expermenting with magento modules and the twitter API. Here is the tutorial http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento/
I got as far as page two where I have a module menu in management that calls on my AdminController’s indexAction like so:
<?php
class Optimise_Twits_AdminController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->getLayout()->getBlock('content')->append($this->getLayout()->
createBlock('twits/helloWorld'));
$this->renderLayout();
}
}
So this displays the block/HelloWorld.php block:
<?php
class Optimise_Twits_Block_HelloWorld extends Mage_Core_Block_Template
{
protected function _toHtml()
{
return 'Hello world';
}
}
?>
THis all works fine, I can navigate to my management menu click on the menu item and I see ‘HelloWorld’. What I want to do is load a template file here instead of displaying text through a class.
I have a form that I want to display that looks up all the products and displays them. I can then choose a product and write in tags and when I click the submit button on the form it formats the data and punts it over to twitter as a status update.
Am I going about this wrong? (should I not be using templates here?) if not can someone help me out with where to put my templates and how to call them.
This is what my phtml file will hopefully look like:
<div class="simple_contact">
<h1 class="cms">'Tweet up' Your Products</h1>
<form id="twitter-feed" name="twitter-feed" action="[action_here]"
method="post">
<table><tr>
<?php
$model = Mage::getModel("optimise_twits/products");
$products = $model->getProducts();
$i = 0;
foreach ($products as $product)
{
// var_dump($product);
echo '<tr>';
echo '<td>';
echo '<label for="'. $product .'">' . $product . '</label>';
echo '<input type="hidden" name="tweet['.$i.'][product]" value="'.
$product .'">';
echo '<br />';
echo '<input type="text" class="hashtag" name="'.
'tweet['.$i.'][tags]" id="tags" value="#enter, #product, #hastag"';
echo '</td>';
echo '<td>';
echo '<input type="checkbox" name="tweet['.$i.'][chk]" id="'.
$product .'"></td>';
echo '</tr>';
$i++;
}
?>
<tr>
<td colspan="2"><input type="submit" name="submit" value="tweet"></td>
</tr>
</table>
</form>
</div>
Thanks a lot!
Jonesy
Magento: load template file from admin module
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed