Probably, it is a simple answer but I cannot find any documentation regarding this. I have laid out a form using Laravel 4 and it seems to be working fine but now I need to style it. How can I add classes to the form when its using blade?
{{ Form::open(array('url' => 'foo/bar')) }}
I have a class set up for the form and the buttons but I am not sure how to add it to the blade template.
You may try this
{{ Form::open(array('url' => url('foo/bar'), 'class'=>'form', 'id'=>'frmFoo', 'style'=>'border:solid gray 1px')) }}
You can add inline style, class, id etc.
As far as I know, you can easily pass additional attributes to the open() methods argument:
echo Form::open(array('url' => 'foo/bar', 'method' => 'put', 'class' => 'form-bootstrap'))
Check out the L4 docs for more information http://laravel.com/docs/html
Related
I am using both cwidgets i.e., cdetailview and cgridview I have displayed it using renderPartial method .
The thing thing is That I need to change my css to it for beautification.I am well versed with css styling but to these widgets, how do I apply it in yii? thats the big question to me, I did walk through all forum pages yet my need is not satisfied.
following is the code
viewb
<?php $this->widget('zii.widgets.CDetailView', array(
'data' => array(),
//to avoid error
'attributes' => $res,
'cssFile'=>Yii::app()->request->baseUrl.'/css/mecss.css',));
?>
cssFile doesn't work have copy pasted the assets detailview code and applied my css yet no change
controllerb
$this->renderPartial('viewB',array('res'=>$res));
viewc
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>true,
'columns'=>array(
array('name'=>' Name','value'=>'$data["name"]'),
array('name'=>' status','value'=>'$data["status"]'),
),
));
?>
controllerc
$this->renderPartial('viewc',array(
'dataProvider'=>$dataProvider,
));
this is the view what am looking for
all the attributes are from the same table's record which i have provided as $res to detailview but then i need deatils, credential details and expirarydetails as headers for respective attributes .is it possible? if yes please guide else what else can i do so to achieve it please let me know.
am displaying it in modelA and modelD view respectively using ajax
to each i wanna apply my css style but then i dont know how do i start
i do know their's an attribute cssFile am tryng with it can anyone guide for it or any good way.
Please guide let me know how do i achieve it
Yes you can apply your custom Css. Some attributes are used for this like
cssFile
filterCssClass
itemsCssClass
loadingCssClass
pagerCssClass
rowCssClass
rowCssClassExpression
summaryCssClass
And yes here is the demo with custom Css properties.
http://www.yiiplayground.com/index.php?r=UiModule/dataview/gridStyle
you can set all sorts of classes for your CGridView :
class for your row
class for filter row
rowCssClassExpression
a PHP expression that is evaluated for every table body row and whose
result is used as the CSS class name for the row.
The following code will apply CSS class from Bootstrap 3 framework to detail view:
<?php
$this->widget('zii.widgets.CDetailView', array(
'data' => array(),
'htmlOptions' => array('class' => 'table table-striped table-bordered table-hovered table-condensed'),
//to avoid error
'attributes' => $res,
'cssFile'=>Yii::app()->request->baseUrl.'/css/mecss.css',));
?>
Basically, you can use the htmlOptions property to apply whatever style or HTML attribute you want (everthing, based on tag name).
I could do this with Javascript, but I was wondering if I could add a css class to specific symfony2 form choices (not the choice field itself, but the individual choices).
For example I want to apply different css styles to individual 'option' tags inside a 'select'. I could only find a way to add a class to the tag.
Thanks in advance.
I think you can simply do:
{{ form_widget(form.name, { 'attr' : { 'class' : 'myClass' } }) }}
... as explained here, without creating your own form style.
You can override the layout of specific widgets in your form, which means you can override the way the select renders and put in custom code to check what the value of the option is and output your custom class there.
You need to apply a custom layout to your form, like so
{% form_theme form 'form_theme.html.twig' %}
Then inside the layout file you need to override the specific field for that specific form (unless of course you want to edit the choice_widget directly in which case all fields that use choice will have the functionality).
To do that you have to copy the widget, so choice_widget, then name it [_formName_fieldName_widget]
So if your form name was events and your field name was requireTickets, it'd be _events_requireTickets_widget
The answers that were already provided are very good, and I think #CriticalImpact's is the most flexible. But I just wanted to mention that if you're using a form class, you can also add extra attributes to the field via the form builder definition itself:
class SomeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('someField', "text", array("attr" => array("class" => "someCssClass")))
->add("save", "submit");
}
}
I've found this helpful for basic forms, because it still allows you to make a simple {{ form(someForm) }} call in your Twig file.
(Note that this solution still has the drawback that #CriticalImpact mentioned above)
Add attributes like CSS styles to individual choices can nowadays be achieved with choice_attr, e.g.:
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
// ...
$builder->add('attending', ChoiceType::class, array(
'choices' => array(
'Yes' => true,
'No' => false,
'Maybe' => null,
),
'choice_attr' => function($val, $key, $index) {
// adds a class like attending_yes, attending_no, etc
return ['class' => 'attending_'.strtolower($key)];
},
));
Okay, I know I can't literally call a twig template function from a controller, but to make links, I usually do the {{ path('_routeName') }} and that's great.
However, now I want to formulate some links in the controller that will then be passed to the template via parameters like this:
$params = array(
'breadcrumbs' = array(
'Donuts' => '/donuts',
'Bearclaws' => '/donuts/bearclaws',
'Strawberry bearclaw' => null,
),
);
return $this->render('Bundle:Donut:info.html.twig', $params);
Except I don't want to hard-code those links. What I'd like is to be able to do
'Donuts' => path('_donutRoute'),
but how to reach the path method or equivalent?
If your controller is extending the Symfony2 Controller (Symfony\Bundle\FrameworkBundle\Controller\Controller) you can use the following to generate urls like this :
$this->generateUrl('_donutRoute')
If you want it with parameters use the following:
$this->generateUrl('_donutRoute', array('param1'=>'val1', 'param2'=>'val2'))
I found an alternative way to do this that I feel is equal to the one proposed by #d.syph.3r
The plan is to do:
'breadcrumbs' = array(
'Donuts' => 'donutsRoute',
'Bearclaws' => 'bearclawRoute',
'Strawberry bearclaw' => null,
)
Then in the twig template, do:
{% for name, route in breadcrumbs %}
{{ path(route) }}
The advantage here is that the Controller is not generating any HTML in this case.
I'm using a sfWidgetFormSelect widget to render a select list. More precisely i'm using the feature allowing groups, quite easy with this :
$choices = array(
'Europe' => array('France' => 'France', 'Spain' => 'Spain', 'Italy' => 'Italy'),
'America' => array('USA' => 'USA', 'Canada' => 'Canada', 'Brazil' => 'Brazil'),
);
$w = new sfWidgetFormChoice(array('choices' => $choices));
That's a good start but not enough because i need to have specific CSS classes attached to each item of the list.
How can i do that ? The doc is not really helping for this kind of advanced features.
Thanks.
Having played with these a little bit, from what I know, this level of control isn't possible via the form class. You can pass the CSS class to the main widget but it would apply to all <option> tags inside the <select>.
You might be better of just writing this dropdown yourself in HTML and making sure it corresponds to this widget in terms of how it's named. This way you can use your own HTML but still use the widget in validation. Another option might be to handle the advanced styling via Javascript where you can connect it to the option values themselves, although it does get a little messy.
I'm trying to theme a modules output.
In particular i'm working on http://drupal.org/project/service_links
Any idea how that works?
Thanks in advance!
Generally, if you want to theme a module you have a few options.
Overwrite theme functions. You can overwrite the theme functions that the module uses/implements to change the markup, one example of such a function is theme_service_links_node_format. You change make a function in your theme's template.php called 'your_theme_name_service_links_node_format' and make your custom markup in it instead.
CSS. If you don't need to change the actual markup of a modules output, you only need to add the needed css, to theme it into your liking.
In some cases, it doesn't look like sercive links is such a case, you can also make your own templates, and make Drupal use them instead.
Another way, again it doesn't look like service is service links is such a case, is to implement preprocess functions in your template.php. This is needed if you want to alter how certain template variables are generated.
If you want to implement your own theming function services links defines 3 themables. In your theme you should imlement the following
yourtheme_service_links_build_link()
yourtheme_service_links_node_format()
yourtheme_service_links_node_format()
'service_links_build_link' => array(
'arguments' => array(
'text' => NULL,
'url' => NULL,
'title' => NULL,
'image' => NULL,
'nodelink' => NULL,
),
),
'service_links_node_format' => array(
'arguments' => array('links' => NULL),
),
'service_links_block_format' => array(
'arguments' => array('items' => NULL),
),
Have a look at http://drupalcode.org/viewvc/drupal/contributions/modules/service_links/service_links.module?view=markup line 389 and below
What's the problem? I mean, every module should use a different name for main container and so. You can use css selector in clever way to refer the template pages.
For example, the FAQ module use identificator to all part of html output, like faq-question and faq-answer in the main page.
Just inspect your resulting code and css it, if possible modify the module-related css!
If the module implements its own theme hooks you can use that. You can also use CSS.