How to load a magento view (.phtml) file from a controller - php

Im trying to load a rendered version of the cart sidebar, which i intend to load via ajax... I've been searching around alot and it seems like the best approach is to create a custom module which will handle all my ajax request. I have created a custom module and everything seems to be working however when I display the sidebar.phtml it is not rendered properly. It displays as if there is nothing in the cart. (im assuming its just trying to reading the file without using any session info). I've search a bunch but nothing seems relevant to what I'm trying to do.
This is the code im using in my custom controller to load the phtml file which is essentially a copy and past of the checkout/cart/sidebar.phtml file.
$layout = $this->loadLayout();
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'PPWD_Custom',
array('template' => 'custom/custom.phtml')
);
echo $block->toHtml();
Thanks

The problem is in incorrect block type. Instead of Mage_Core_Block_Template you should use Mage_Checkout_Block_Cart_Sidebar. Like this:
$this->getLayout()->createBlock(
'checkout/cart_sidebar',
'PPWD_Custom',
array('template' => 'custom/custom.phtml')
);

Related

Silverstripe: Top.PageControllerFunction not displaying

I am using the Silverstripe Twitter module. It has a page controller function called LatestTweets($value) Which obviously displays the latest tweets.
When I add the Latest Tweets function to the Page.ss template. The tweets display. Everything works fine.
I am also using shaedawson's blocks module. I have a 'grid' block. The Grid Block has a template (Grid.ss) In the Templates Folder (templates/). When I add $Top.LatestTweets(3) to the Grid Template, the tweets do not appear.
Can anyone explain why this is happening?
It works on any page controller, because the module tractorcow/silverstripe-twitter enables extension TwitterExtension on the Page_Controller in its configuration.
Blocks in sheadawson/silverstripe-blocks module are rendered with SiteTree context (the top scope) and your LatestTweets() function is not available.
So, the only remedy is to enable the TwitterExtension on your Page.
I figured this out. The reason why the "Latest Tweets" function was not appearing on my template, was because I had to extend Block_Controller
I added the following to my 'extension.yml' file:
Block_Controller:
extensions:
- TwitterExtension
I would like to be able to 'include' the "Twitter Feed" template in my Grid Template. However this works and will do for now.

Render output of a php file inside a div as a sublayout in a component view as virtuemart sublayout

I am using Joomla 3.5.1, and i have a component and a system plugin,
In one of my view in the component i m checking if the plugin is installed then i am creating a div, In this div i want to render a php file as a sub layout, the file i want to render will be part of the plugin installed.
How to use the file as a sub layout, please provide some ideas i tried using JLayoutHelper but i couldn't accomplish it.I tried searching but got no successful results.
In view:
$plu=JPluginHelper::getPlugin("system", "myplugin");
<?php if(count($plu)!=0){ ?>
<div class="panel-body contentbar">
<?php $layout = new JLayoutFile(JPATH_SITE."/plugins/system/myplugin");
$layout->render("mycus.php");
?></div><?php } ?>
What am I suppose to do to achive this.
You are not giving the correct syntax for JLayout
Instead of this
$layout = new JLayoutFile(JPATH_SITE."/plugins/system/myplugin");
$layout->render("mycus.php");
Try this code
$layout = new JLayoutFile('mycus', $basePath = JPATH_ROOT .'/plugins/system/myplugin');
$layout->render($params);
will load and render the 'mycus.php' layout file found in JPATH_ROOT .'/plugins/system/myplugin' directory. $params are the parameters to be passed to that file.
Check this page https://docs.joomla.org/J3.x:Sharing_layouts_across_views_or_extensions_with_JLayout

How to change Sign up page design in Moodle

I am new to moodle and i am using 2.9. I have a separate design for Signup page (HTML5 & CSS). How to integrate this page ?
I know the process of changing the default Login page like this
In config.php of my theme
'login' => array(
'file' => 'login.php',
'regions' => array(),
'options' => array('langmenu'=>true),
),
Where my Custom login page is login.php which is placed in my layout folder. So in this way i can takeover Login page design with my new design.
But i don't see any signup array in config page for Registration. So anyone can tell me how to do this change ?
Edit - I have checked this file moodle2\login\index_form.html I can see the signup design. But my issue is that file index_form.html has Moodle core CSS if i add my CSS there it will conflict also i dont know how to load the CSS from my theme folder to index_form.html.
Can anyone guide me ?
I already checked Moodle.org forum but not able to find the process.
Thanks In Advance
Lorry
Further to what #davosmith mentioned, you can actually use the existing auth/email plugin as a base for your plugin, So:
Copy auth/email and rename it to whatever you want, for example auth/foo. And rename all other instances of "email" to "foo".
Copy the login/signup_form.php to your plugin directory
in your auth/foo/auth.php file, add a function:
function signup_form() {
global $CFG;
require_once($CFG->dirroot.'/auth/foo/signup_form.php');
return new login_signup_form(null, null, 'post', '',
array('autocomplete'=>'on'));
}
Modify the auth/foo/signup_form.php to whatever you want
Hiii,
I'm one of the Moodler who working with Moodle.
to edit the signup page go at the following location and open the signup.php file.
./moodle/login/signup.php
in that file you can see at bottom of the page three lines.
...
echo $OUTPUT->header();
$mform_signup->display();
echo $OUTPUT->footer();
in which $mform signup->display(); create a form yu can comment and write HTML for your sign up form.
But make sure about the Action URL and the validations.
$mform is the object that create form and its class file is signup_form.php.
Hope it helpful for you ... Good Luck ['}
If you are wanting to avoid making changes to the core code in Moodle (which should almost always be what you want), then you can create a new signup form from scratch by first creating a new authentication plugin (in auth/NAMEOFPLUGIN).
When you create the authentication plugin, you should make sure that the 'can_signup' function returns true, that the 'user_signup' function does whatever processing is needed to create the new user account and that the 'signup_form' function returns a custom Moodle form that contains the fields you want.
It is possible to further customise this form by outputting custom HTML elements (using $mform->addElement('html', 'The HTML to output'); ). I would not advise completely abandoning the Moodle form (i.e. to replace it with hand-coded custom elements), as that will not be compatible with the signup code in login/signup.php (as well as losing the validation rules that are supported by the forms library).

ViewScript decorator unable to set

I am following the section about "Full Customization Using the ViewScript Decorator" from this page -> http://devzone.zend.com/article/3450
In the init method of my form class I have added this
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
Now in the place where my form appeared I have this:
An error occurred
Application error
What am I doing wrong here? I really need to customize the appearance of the form and I just want to change the form and not the appearance of the whole page.
I have tried this:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
Which works but affects the display of the whole page (I am using zend layout). I just need the render of the form to be passed to the display.phtml page.
Note: Is there any place in particular I have to place the display.phtml? I placed it in the view\scripts folder.
I think it is as simple as this.
The ViewScript cannot be used in the init() method for your form for one simple reason. If you look at the example (and probably your display.phtml) there are echo statements like this one $this->form->firstname;. At this point in init() the form elements are not loaded yet!
The author therefore correctly shows this code
$form->setDecorators(array(
array('ViewScript', array('script' => 'demogForm.phtml'))
));
Note that he uses $form as the object. Either in controller or view script you load your form as an object and then add the ViewScript. So in one of your controllers you would do something like this
$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
array('ViewScript', array('script' => $scriptPath))
));
This should do the trick.
Update Looking at the naming of your pthml I assume (and hope) this is a special template for your form and not your whole layout file. If you use your whole layout file then of course if will render the whole page!
When working with view scripts, I find it's best to make any such changes at the view level.
Ignore the "ViewScript" decorator details in your form and set them from the view, eg
<?php echo $this->form->setDecorators(array(
'PrepareElements',
array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>
The location of the display.phtml file is relative to the module's view scripts folder. If this is just the default module (under the application folder), the script in my example will be located at application/views/scripts/_forms/display.phtml
If you want to remove HTML tags like <dt> or <dd> (labels and viewscript) you can use methods removeDecorator('HtmlTag') or removeDecorator('Label')

CJuiautocomplete with multiform model

I am using a multi form model. A $model array is passed to the view and for each model object I am trying to have a text field and it works fine this way. See the code below.
foreach ($model as $f=>$edu):
echo $form->textField($edu,"[$f]schoolname",array('size'=>30,'maxlength'=>128));
I am trying to have an autocomplete text field coded replacing the activeform text field. It is not working. Any ideas how to make this work.See the code below.
foreach ($model as $f=>$edu):
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$edu,
'attribute'=>"[$f]schoolname",
'source'=>$this->createUrl('AutoComplete/acschoolname'),
// additional javascript options for the autocomplete plugin
'options'=>array('showAnim'=>'fold',),
'htmlOptions'=>array('size'=>'30','maxlength'=>'128',)
));
This appears to be a bug in Yii. Tabular form input is broken with widgets.
A workaround was posted in the Yii forums. I haven't tested it, but it's reported to work:
http://www.yiiframework.com/forum/index.php?/topic/10685-collecting-tabular-input-with-zii-jui-widgets-is-broken/
Baiscally, around Line 82 in CJuiAutoComplete.php, comment out the following lines:
//else
//$this->htmlOptions['name']=$name;
To make sure you are not modifying the Yii core and breaking upgrades, I would copy CJuiAutoComplete.php in to your /components folder and rename it MyJuiAutoComplete or something, and call that instead of CJuiAutoComplete.
Good luck!

Categories