Can I set different background color to views page dynamicaly - drupal-theming

I'm new to drupal,
I'm getting users favorite color from cck color picker then I want to set it to the background of the profile page. Profile page i created using views. I tried to do it from crating view tpl file but no luck is any way to do that task please direct me

this is obviously not complete code, as you need to figure out how to call the field data. I haven't tested this, but in theory this should work. Add this to the .tpl.php file, and see if it works.
<?php
header('Content-Type: text/css');
/*replace cckmachinename and fieldmachinename with actual code*/;
$user_color = cckmachinename -> fieldmachinename
?>
some selector {
background-color: <?php echo $user_color; ?>;
}
Hope this helps!

Related

how to disable button using jQuery in yii

i want to disable update button dan make it invisible using jQuery when update page is open, but if the value of payed is 1. i can get the value from database
somebody please help me, i'm a newbie in yii. thank you
Add this code to your view file:
<?php Yii::app()->clientScript->registerScript(
'disable-button',
'$('input[type="submit"]').attr('disabled','disabled');',
CClientScript::POS_READY
) ?>
But change jQuery selector on yours:
$('input[type="submit"]')

Zend Framework 2 - Make content page variable accessable in layout.phtml

I want to build a fancy headline container which - you'll never guess it - contains the title of each page displayed.
In Django you can either create a variable in every view which is passed to the layout page or define a block which is filled with content on the content page.
Its not such a nice solution copy and pasting my fancy header on every page of my application just to put my page title in. I'd prefer to put the headline container in my layout page and use my $title variable to set the title within the container.
I found a solution for static variables here but I need a dynamic variable because the title is different for every page.
My question: Is there an easy way to pass the $title variable which I have on every content page to my layout.phtml?
Thanks!
There is a nice view Helper in ZF for this task. You can define what Title you want to use for your page in your view files.
In your view pages:
//index.tmpl
$this->headTitle("this is my unique title for this page");
In your Layout file :
<title><?php echo $this->headTitle() ?></title>
And more info at: http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.head-title.html
Ok, the answer is quite simple if you know what to look for. Use the placeholder helper.
//layout.phtml
<?php $this->placeholder('foo')->set("Some text for later") ?>
and
//myview.phtml
<?php
echo $this->placeholder('foo');
// outputs "Some text for later"
?>

Yii - how to preload a widget

I am working with Yii Jui widgets to have JuiTabs in a website. The problem is when the site is loading I first see the list (without any css) and then after the page loads the tabs show as they should. I wonder if there is a way to preload JuiTabs somehow so they show correctly when the page is loading.
Here is my code:
<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'PRESENTAZIONE'=>array('content'=>$this->renderPartial('spettacoli/_view_presentazione', array('model'=>$model),$this)),
...
),
'options'=>array(
'collapsible'=>false,
),
));
?>
And here is the example of the page. The problem is visible when the internet connection is slow, and it takes time until the page loads
Not sure that's possible to preload JuiTabs somehow, but you can add display: none for CJuiTabs by default and show that with JS on page load. Not the best way, but first idea came into my mind.

Invoke action in Yii

This is my scenario. A home page with a upload form, user upload the images and submit, then the controller will catch the data from user, add it in the Model. Finally the image info will display in the another page.
I put the actionIndex() in the siteController to render the home page, the actionUpload() in the same file to handle the data user. So in the view, what should I put in the form action to invoke the actionUpload(). I think the flow is quite weird in Yii when I read the blog demo code, I just follow same way with the ASP.NET MVC. Suggest me the right way, plz. Thanks
Depends on how you build your form. If using CHtml, do the following:
<?= CHtml::beginForm($this->createUrl('site/upload'))?>
If you have a model that sits behind it:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'action' => $this->createUrl('site/upload'),
)); ?>
Please check the Yii documentation and examples on how to properly set up forms. You have several choices here.

separate header, content and footer in yii

I have a login form in my header section of the website. If user is logged in than insted of the login form user profile details will be shown. The question is how to separate header footer and content into different views and call them from one controller? Or maybe there is another solution...Thanks for help.
In your header view you could write something like this.
<?php if(Yii::app()->user->getId()): ?>
<?php $this->renderPartial('//world/_header_user')); ?>
<?php else: ?>
<?php $this->renderPartial('//world/_header_guest')); ?>
<?php endif; ?>
Using the Model-View-Controller (MVC) design pattern, the look of a Yii-based site is naturally controlled by the View files. These files are a combination of HTML and PHP that help to create the desired output. Specific pages in a site will use specific View files. In fact, the View files are designed to be broken down quite atomically, such that, for example, the form used to both create and edit an employee record is its own file, and that file can be included by both create.php and update.php. As with most things in OOP, implementing atomic, decoupled functionality goes a long way towards improving reusability. But the individual View files are only part of the equation for rendering a Web page. Individual view files get rendered within a layout file. And although I’ve mentioned layouts a time or two in my writings on Yii, it’s a subject that deserves its own post.
To be clear, layouts are a type of View file. Specifically, whereas other View files get placed within a directory for the corresponding Controller (i.e., the SiteController pulls from views/site), layout files go within views/layouts. But while the other View files are associated with individual Controllers (and therefore, individual pages), layouts are communal, shared by all the pages. Simply put, a layout file is the parent wrapper for the entire site’s templating system. I’ll explain
ypu can see more details
http://www.larryullman.com/2012/05/16/working-with-layouts-in-yii
The easiest way is probably to use a different layout, which you just switch on login. If not, showing partials / components based on Yii::app()->user->isGuest also works well.
Your default generated Yii application has a parent Controller in protected/components/Controller.php.
If you need to access additional parameters in layout, add public properties to Controller, set them in your child controller, and use them in your view/layout files.