Drupal 7 node custom template or core display - php

I have dozens content types in which I need to display more or less block of the same fields. Using core display I have to create many groups and even than styling them with css is tricky.
My alternative is to use template suggestions but will they render faster than normal display method I'm currently using?
It will be easier to remove thoose fields from display, write the templates and render node in template (all the other data).
But how about performance?
Any help will be appreciated
Thanks

Although the answer is not so specific I would say that printing what you need in tpl.php files is faster than hidding them with css or php if conditions. So you should better use tpl.php files for each node type. And "core method" you are talking about is using tpl.php files! Look inside ROOT/modules/node folder for the tpl files of node module.
There are also some useful modules to help you with that like display suite, panels, entity_view_modes etc but if performance is a big issue you can go without them.

Related

Specific template loaded with php

I have a joomla component and I want to have a custom template depends on the resolution.
I have default_list.php file where I want to include a php code to load a specific template (default_list_template1.php) depending on the device resolution.
Can someone give me a clue?
Since there is no simple way to get screen-resolution with PHP (server-side language), and moreover, resolution may change over time (screen resize), it is much better to start with responsive CSS well explained at http://learn.shayhowe.com
If you want to dig on your own, use "responsive website" and "CSS media queries" search phrases.

SASS and/or LESS - can I create dynamic CSS files on the fly?

I'm using CakePHP to build my site (if that matters). I have a TON of elements/modules each having their own file and fairly complicated CSS (in some cases).
Currently the CSS is in a massive single CSS file, but for sanity sake (and the below mentioned details), I would like to be able to keep the CSS in it's own respective file - ie css/modules/rotator.css. But with normal CSS, that would call a TON of CSS files.
So, I started looking into SASS or LESS per recommendation. But - it seems these are supposed to be compiled then uploaded. But in my case, each page is editable via the CMS, so a page might have 10 modules one minute, then after a CMS change it could have 20 or 5...etc. And I don't want to have to compile the CSS for every module if it's not going to use it.
Is there a way I can have a ton of CSS files that all compile on the fly?
Side note: I'd also like to allow the user to edit their own CSS for a page and/or module, which would then load after the default CSSs. Is this possible with SASS and/or LESS?
I don't need a complete walkthrough (though that would be awesome), but so far my searches have returned either things that are over my head related to Ruby on Rails (never used) or generic tutorials on each respective CSS language.
Any other recommendations welcome. I'm a complete SASS/LESS noob.
Clarified question:
How do I dynamically (server-side) combine multiple CSS files using LESS? (even a link to a resource that would get me on the right track is plenty!)
If you want to reduce the number of CSS files & you have one huge css file that has all the component css, just link to it on all pages & make sure you set cache headers properly.
They will load the file once and use it everywhere. The one pitfall is initial pageload time; if that's not an issue go with this solution. If it is an issue consider breaking down your compiled CSS files to a few main chunks (default.css, authoring.css, components.css eg.).
Don't bother trying to make a custom css for each collection of components, you will actually be shooting yourself in the foot by forcing users to re-download the same CSS reorganized in different ways.
Check out lessphp (http://leafo.net/lessphp/). It's a php implementation of less and can recompile changed files by comparing the timestamp.
Assuming that 'on the fly' means 'on pageload', that would likely be even slower than sending multiple files. What I would recommend is recompiling the stylesheets whenever a module is saved.
The issue of requiring only necessary modules should be solved by means of CMS. It has nothing to do with SASS or LESS.
If your CMS is aware of which modules current page has, do not run a SASS/LESS compilation (it will be painfully slow unless you implement caching which is not a trivial task). Instead, adjust your CMS's logic so that it includes each module's CSS file.
Advanced CMSs like Drupal not only automatically fetch only necessary CSS files, but also assemble them into a single file and compress it.
And if your CSS is not aware of which modules current page has (e. g. "modules" are simply HTML code that is saved into post body), then you can't really do anything.
UPD: As sequoia mcdowell says in his answer, making users download one large CSS file once is better than making them download a number of lesser CSS files that contain duplicate code. The cumulative size of all those smaller CSS files will turn out to be larger than the size of a full CSS file.

html and css in mysql

I am having trouble designing a solution to a complex problem. I am building a site that creates html templates including both the css files and html files. Users will be able to create multiple templates/sites.
In an attempt to create a normalized database I have a user table (id, name, email, password, etc.), a site list table (user_id, site_id, site_name, description), and the rest I am having trouble figuring out.
I am trying to develop a way to break down both the html files and css files into a database that can be used to reproduce the designed template. Constant editing and adding to the database will take place when creating/editing a template. Basically, an extremely simplified dreamweaver. Flat files may be an option as well.
Any input or suggestions on how to go about such site would be greatly appreciated such as how to break down the html and css into mysql tables/records. Im not so much looking for code, but the fundamental concepts/workings of such a site. Thanks in advance.
First of all, are you sure you even want to store that content in the database? That's going to place a heavy burden on your servers over generating them as files onto the filesystem inside the DocumentRoot and directly servable by the web server. I can see storing the configuration options (color choices, image names, etc) in the database, but not the files themselves.
Can these websites have any content the customer wants, or are they variations on a theme? If it's the former, then you really can't automate it much. You can store the content in a database instead of a file, but it won't really be advantageous.
Your best bet, I think, is to look how CMS programs like WordPress/Joomla break up a page into separate include files (header, footer, left menus, right menus, etc) and use that as a model. The customer picks a template, and each template has defined sections that can be laid out separately with different content.
You could store the templates in text files then store settings (such as CSS attributes or images they may want) in the database. That way, you just load the template with the applied settings.

First Larger-Scale Web Dev Project - Advice for Content Management?

I'm familiar with HTML, CSS, and some PHP and Javascript. I've made several fairly complicated websites for which I've acted as webmaster, manually adding all content in HTML.
I'm about to put in a proposal for my first outside client at a larger business. They have an IT person that would be responsible for updating the website that I create for them.
My question is what to do about content management. I've looked into things like Drupal, but they seem overly complex for this kind of situation, with a single person adding updates of things like text, images, and PDFs.
What would you recommend as the next step above the simple way of manually uploading files and editing HTML like I'm used to? Something like a MySQL database and PHP calls? Would I then store all the images in the database as well?
I guess I'm just trying to figure out what's most common at a medium-sized business. I appreciate any guidance you can offer!
Nathaniel
My company has built large scale projects and medium scale as well. What we like to do is setup a outer page with navigation and an inside page that the client has control of by a control panel with FCK Editor or TinyMCE.
So essentially we have a wrapper page (in our case a MasterPage but in PHP you would use an include or a index.php with a query string to pull the content) and then we drop in HTML content from the database.
That database is populated by the client in their control panel. FCK Editor allows them to upload images and manage links, etc.
For our bigger clients we get very specific in our control panel allowing them to add videos, PDF attachments, blog entries, FAQ content, etc.
Some examples we have are http://pspwllc.com and http://needsontime.com and http://nwacasa.org
Drupal can be bit complex at first but if you stick with the basic modules - it is great for website content management.You can write your own mini content management system - store text and images(MySQL blob format) in MySQL.It will be couple of PHP admin pages and a good render() function responsible for page rendering.
Also have a look at wordpress, it is much easier than drupal. It is less powerful but it may serve your needs. You will NOT need to configure modules like FCKeditor, with it bcoz they come inbuilt. Anybody will be able to edit the content easily. Do note that wordpress is not just for blogs, you can create different kinds of websites with it. Another choice is Joomla, it is also simpler than drupal. But, wordpress is the simplest.

What are best practices for determining if I should create a new Drupal module?

I'm using Drupal for the first time for a project at work. I'm finally getting my head wrapped around some of the core concepts, but when it comes to customizing output I'm unsure of how to proceed.
I have to build a fairly specialized image gallery. I've managed to cobble something workable together using Views2, but it's not quite where it needs to be. I'd like to write it from scratch, using SQL and actual PHP, rather than working through this web UI.
I figure I'll put this functionality in a new module. Is that right? Or is that an abomination to the Drupal world?
Edit:
Here's what I've got so far. I've created Image Gallery and Image content types with CCK. Images can be assigned to multiple galleries, via nodereference. I've got imagecache creating two sizes for each uploaded image - a thumbnail size and a gallery size.
Two gallery formats are required, but let's assume I'm going to have a carousel style for now, with some custom JQuery and CSS to match the rest of the site's look and feel. Clicking a thumb in the carousel-style navigator will load the full sized image above it.
Now, assuming such a thing does not exist, what is the recommended approach for creating it? Not how to code it, but where would this code live within the Drupal system?
It seems like views will do the job of creating the data you need - a list of all the images for the galleries, based on whatever criteria you need (taxonomy,author or whatever) and that the carousel part - adding the jquery and css could be done by using drupal's themeing system to change the output.
So as ar as 'where would the code live' I would say in your theme, rather than a module.
The views theming system is pretty comprehensive, if possibly a little overwhelming at first.
This looks like a good starting reference: http://www.group42.ca/theming_views_2_the_basics
You can do this. Views is great but will often only get you 90% of what you need out of the box.
You can do views theming, which can take you further, and you can write extentions to the views functionality (but that is not always easy).
There is nothing wrong with writing your own module in stead of views, in some cases it can increase performance. One tip if you are doing this is that you can see use the query that views creates in your custom module, this can save you having to work it out and write it yourself.
Yep, I'd put this in a module. I often wind up writing custom ones for specialised use cases.
Well since it is free software you are free to do (almost) whatever you want with it.
A good practice to decide if you should do it is:
Will the benefits that I will get from
a custom module divided by the time
I'm going to invest in it. Outweigh
the benefits / over time of a solution
that isn't ideal?
Or if you prefer to look it this way:
Custom Development Benefits Not 'ideal' solution benefits
--------------------------- > -----------------------------------
Development Time Time to install and adapt
Since normally the Time to install and adapt normally is smaller than the time to develop something from scratch, the common conclusion is to just use what is already there.
But by all means if you want to develop your own thing and have enough time, go ahead.

Categories