0

On a button click, when my controller redirects to a new form, i want my custom phtml file to be called from the block.

But neither my Block or my phtml does seem to be called.

I guess I have missed some link somewhere

I have done as below:

config.xml

<config>
<modules>
    <Vendor_Recipe>
        <version>1.0.0</version>
    </Vendor_Recipe>
</modules>
<global>
    <blocks>
        <vendor_recipe>
            <class>Vendor_Recipe_Block</class>
        </vendor_recipe>
    </blocks>

    <models>
        <vendor_recipe>
            <class>Vendor_Recipe_Model</class>
            <resourceModel>vendor_recipe_resource</resourceModel>
        </vendor_recipe>

    </models>

</global>
<frontend>
    <routers>
        <vendor_recipe>
            <use>standard</use>
            <args>
                <module>Vendor_Recipe</module>
                <frontName>vendor_recipe</frontName>
            </args>
        </vendor_recipe>
    </routers>
    <layout>
        <updates>
            <vendor_recipe>
                <file>vendor_recipe.xml</file>
            </vendor_recipe>
        </updates>
    </layout>

</frontend>

I have a button here:

\app\design\frontend\base\default\template\vendor_recipe\recipe\customer\comment\list.phtml

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title">
  <form action="<?php echo $this->getUrl('vendor_recipe/manageRecipe/addRecipe') ?>" method="post" id="form-validate" autocomplete="off">

    <button type="submit" class="button" title="<?php echo $this->__('Add New Recipe') ?>">
        <span><span><?php echo $this->__('Add New Recipe') ?></span></span>
    </button>
</form>

Where in :

\app\code\local\Vendor\Recipe\controllers\ManageRecipeController.php

  <?php
 class Vendor_Recipe_ManageRecipeController extends  Mage_Core_Controller_Front_Action
 {
 public function addRecipeAction()
{
    //echo 'Add recipe';
    $this->loadLayout();
    $this->renderLayout();
}

}

Calling addrecipe.phtml from layout as:

\app\design\frontend\base\default\layout\vendor_recipe.xml

<vendor_recipe_recipe_customer_manage translate="label" module="vendor_recipe">
    <label>My Recipes </label>
    <update handle="customer_account"/>
    <reference name="my.account.wrapper">
        <block type="vendor_recipe/recipe_customer_managerecipe" name="customer_recipe_add" template="vendor_recipe/recipe/customer/managerecipe/addrecipe.phtml"/>
    </reference>
</vendor_recipe_recipe_customer_manage>

\app\code\local\Vendor\Recipe\Block\Recipe\Customer\ManageRecipe.php

class Vendor_Recipe_Block_Recipe_Customer_ManageRecipe extends Mage_Customer_Block_Account_Dashboard
{

  protected function _construct(){
      echo 'Block ';
  }

}

\app\design\frontend\base\default\template\vendor_recipe\recipe\customer\managerecipe\addrecipe.phtml

<?php
    echo 'ADD';die;
?>
1

2 Answers 2

0

Your class is not properly named.

You need to replace:

Vendor_Recipe_Block_Recipe_Customer_Manage

With:

Vendor_Recipe_Block_Recipe_Customer_ManageRecipe

And in your layout replaced:

vendor_recipe/recipe_customer_manage

With:

vendor_recipe/recipe_customer_manageRecipe
1
  • I have updated the code @Raphael, phtml is still not calling...and should we give managerecipe or manageRecipe in layout?
    – Sushivam
    Nov 2, 2016 at 12:19
0

your xml file contail wrong block name update with below one

\app\design\frontend\base\default\layout\vendor_recipe.xml

<vendor_recipe_recipe_customer_manage>
 <label>My Recipes </label>
 <update handle="customer_account"/>
    <reference name="my.account.wrapper">
       <block type="vendor_recipe/recipe_customer_managerecipe" name="customer_recipe_add" template="vendor_recipe/recipe/customer/managerecipe/addrecipe.phtml"/>
    </reference>
</vendor_recipe_recipe_customer_manage>

or change your layout file as below

<customer_account>
   <reference name="content">
        <block type="vendor_recipe/recipe_customer_managerecipe" after="my.account.wrapper" name="customer_recipe_add" template="vendor_recipe/recipe/customer/managerecipe/addrecipe.phtml"/>
   </reference>  
<customer_account>
7
  • I have updated the code for button and the controller...am i missing any link to the Block?
    – Sushivam
    Nov 2, 2016 at 12:31
  • please provide your config.xml for more detail Nov 2, 2016 at 12:34
  • added the config file
    – Sushivam
    Nov 2, 2016 at 12:43
  • @SachinS check my updated answer Nov 2, 2016 at 12:48
  • If i use the <customer_account> tag, my custom link from the left navigation of the customer account is not coming
    – Sushivam
    Nov 2, 2016 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.