Using Yii2 Bootstrap widgets with Smarty - twitter-bootstrap-3

I've installed Yii2 together with Smarty for my views.
Smarty itself is working, but I can't figure out how to use the bootstrap widgets with smarty, nor find any examples.
With the default Yii renderer the widgets work great, and lots of examples are available. But when using Smarty templates documentation is nearly non existing.
How would I define this example with Smarty ?
echo Alert::widget([
'options' => [
'class' => 'alert-info',
],
'body' => 'Alert widget',
]);
Obviously the first thing would be
{use class="yii\bootstrap\Alert"}
But I can't find an example of how to define the widget itself.

You should simply try this :
{use class='#yii\bootstrap\Alert' type='function'}
{Alert body='Alert widget' options=['class' => 'alert-info']}
Read more : http://www.yiiframework.com/doc-2.0/guide-tutorial-template-engines.html#importing-static-classes-using-widgets-as-functions-and-blocks

After changing config/web.php and adding:
'globals' => ['html' => '\yii\helpers\Html'],
'uses' => ['yii\bootstrap'],
in the view section, it works.
{use class='yii\bootstrap\Alert' type='function'}
{Alert body='Alert' options=['class' => 'alert-info']}
So without the # soju suggested.

Related

Yii2 register Js set Type and remove jquery

i want to have script tag like this for each View
<script type="application/ld+json">
/****** my code
</script>
with
$this->registerJs(....)
i get this kind of code:
<script>jQuery(function ($) {
.....
});</script>
how to add diffrent type and how to remove jQuery..?
By default registerJs() is using $position = View::POS_READY and this one is registering automatically jQuery asset. If you don't want this you can use:
registerJs($js, \yii\web\View::POS_HEAD) - to place JS in the head part
registerJs($js, \yii\web\View::POS_BEGIN) - to place JS in the beginning of body part
registerJs($js, \yii\web\View::POS_END) - to place JS in the end of body part
Unfortunately all these will add your script in the standard <script> tag without the type.
To achieve this you must add it manually either by placing the <script...> by yourself or by calling \yii\helpers\Html::script($js, ['type' => 'application/ld+json']) in your view or layout file.
I use this in the layout. Using blocks allows me to replace this for other schema.org in other pages.
<?= Html::script(isset($this->blocks['schema'])
? $this->blocks['schema']
: \yii\helpers\Json::encode([
'#context' => 'https://schema.org',
'#type' => 'WebSite',
'name' => Yii::$app->name,
'image' => $this->image,
'url' => $this->url,
'descriptions' => $this->description,
'author' => [
'#type' => 'Organization',
'name' => Yii::$app->name,
'url' => Yii::$app->homeUrl,
'telephone' => Yii::$app->params['phone'],
]
]), [
'type' => 'application/ld+json',
]) ?>
Simply use Html::script($js, $options).
Consider the usage of Json::encode() to avoid writing JS in a PHP
file. It's prettier for me that way, and also makes variable
interpolation easier.
In this example you see a lot of $this->image|description|url
because I'm using https://github.com/daxslab/yii2-taggedview to extend the
yii\web\View with more attributes in order to make automate Opengraph
and Twitter Cards tags generation.

Making a dynamic Form in Prestashop

What I want to achieve Image! Hi I am working on a module in prestashop. What I want is that there should be a button (any-name: Add new field) in the backoffice-(Module Configuration page the first page that comes when you configure your module) that the user presses and it should add a new input field in the form. This all should be done using the helper classes. How can I achieve that? Some code would be grateful! I have uploaded an image. I have tried it using jQuery and it works but I need this done using helperForms in prestashop! In jQuery if I press the add new field button it adds an input field dynamically but the helper-classes are not used in that case.
Here is a link to the documentation :
http://doc.prestashop.com/display/PS16/Using+the+Helper+classes
the documentation is for PS 1.6 but it should also work with PS 1.7
Here is an example of code that generate a form with Helper Classes :
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Edit carrier'),
'image' => '../img/admin/icon_to_display.gif'
),
'input' => array(
array(
'type' => 'text',
'name' => 'shipping_method',
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
I don’t know if you can use Helper class for custom forms that update custom datas. I’m sure you can use them to update module configuration and prestashop object (customer, etc.)
Helper classes enable you to generate standard HTML elements for the
back office as well as for module configuration pages.

Yii The view file does not exist - where do mail layouts go

I am using basic template but have adapted the advanced user password reset functionality, for some reason I can't get it to find the mail layouts.
So in \mail\layouts I have
- passwordResetToken-html.php
- passwordResteToken-text.php
In web.php I have
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => 'app\mail\layouts',
...
The advanced template uses
'viewPath' => '#common/mail',
But as i'm using basic template, its not in the common/mail folder.
In sendMail function in PasswordResetRequestForm.php i have
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
...
However getting error
The view file does not exist: app\mail\layouts\passwordResetToken-html.php
I know this is going to be something small but for the life of me i cannot see it
Removed the 'viewPath' of config, as the doc don't use it.
So it works.

yii-booster set up giving me errors

Sorry real new to yii, but where do i put the yii-booster 2.0 files?
I tried putting all the files into the extensions/bootstrap folder.
I then edited config/main.php and added this
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
and
'preload'=>array(
'log',
// 'fontawesome',
'bootstrap',
),
and
'theme'=>'bootstrap',
where I have a theme in themes/bootstrap which I took from my previous installation of http://www.cniska.net/yii-bootstrap/
but I'm getting this error
Bootstrap and its behaviors do not have a method or closure named "register".
from the theme you got from http://www.cniska.net/yii-bootstrap/
try removing this in themes/bootstrap/views/layout/main.php
Yii::app()->bootstrap->register();

enabling layout disables cjuidatepicker yii

I have a small view which renders cjuidatepicker widget.
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'flat'=>FALSE,
// 'model' => $model,
'attribute' => 'start_date',
// 'value' => $model->start_date,
'name'=>'dateSelect',
'options' => array(
'showButtonPanel' => true,
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
));?>
while this renders nicely without using a layout, but when I put this view in my project layout, the datepicker refuses to show up.
I have no ideas where to look for this, all the css and js are loading similarly in layout and without layout.
Any help would be greatly appreciated.
Thanks
Having dealt my fair share with the datepicker, I'm willing to bet money on that the root to your problem is an error in your javascript. Try to comment out all included javascript in your layout and see what happens. For example, maybe you have jQuery included twice, or some code section missing a closing bracket. Basically any js error will throw datepicker off it's game. Just check the js console in your favorite browser.
I had multiple versions of jquery being loaded and that created quite a mess. Yii jquery was different from the template jquery version being used. Brought both of them to an agreement and boom!!