Create Landing Page in Drupal 7 - drupal-7

In Drupal one can basically style the elements, like the search box, or the basic page etc. and then put some content in the site and the resulting page will be generated. But what if you want one specific site (e.g. the index page) to be different? E.g. have a image as a background, a different navigation styling etc.
What's the best paractice way of doing this?

Best practice is to have a different theme which you can switch to by using hook_custom_theme() where you check the current path. Also make sure that your theme to switch to is enabled:
/**
* Implements hook_custom_theme().
*/
function YOUR_MODULE_custom_theme() {
# check path with arg(0)
# return theme name to switch to
return 'different_theme_machine_name';
}
Alternatively you can also try ThemeKey doing this out of the box with an interface & allowing you the specify rules.

If you need to change only the content(body) section of your page, use Disply Suite. You can create unique look and feel layouts for your body section of each page.
If you trying to change the complete layout of one page (eg: Services), Create new Content Type 'Services'. Then create a template file for this content type, You must name this template call page--services.tpl.php. And also you can overwrite the index page layout by creating page--front.tpl.php template. Done!

What you are saying you want to change is all styling. And you know you can do a page to look drastically different with CSS... and you can do it that way depending on your chosen Drupal theme.
Now, with the Chrome Inspector (or FF inspector) look at the body tag, it probably has many classes which indicates in what page you are, what type of node (if it's a node) or if it's an admin section, or an anonymous user.
Using those specific classes you can style a frontpage, or a view, or a node, or anything, without installing more modules... with some limitations because you can't change rendered HTML this way.
Finally, don't get scared by using modules in Drupal, it's how Drupal works and it works pretty well. The thing is to install the best tools to increase your productivity, and Drupal have excellent options to change your theming and content like Display Suite (like #BaikHo suggested).
Hope that helps.
PD: Using the less module and with custom your theme you can have LESS css which is considerably faster than using only CSS, and because it's integrated with Drupal you can theme make everything even faster. Give it a try.

Related

Link to an anchor on another episerver page

Is there an elegant way of linking to anchors in some other page in EpiServer that will keep the links relevant - even after the anchor names change? I am 95% sure there is no standard way of doing this, so thoughts on custom implementations are welcome.
There are existing plugins, but ...
I found this plugin to EpiServer that will basically scrape all the anchors from the page you are interested in, and present them in a drop-down in the TinyMCE wysiwyg editor. But as the anchors have no unique attributes that makes it possible to follow them through changes, these anchor links will rot in time, as changing <a name="Meeting"></a> to <a name="Appointment"></a> will make previously created links invalid.
Thoughts on how this could work
I am not super-familiar with how to easily work with ContentTypes in EpiServer, but I would assume it should be possible to create some kind of property, HtmlAnchors, that would be a collection of strings that could be employed on a page. These would be regarded as constants in practice, and I am quite certain that there is a way in EpiServer of checking if a page property is in use, so if one of these strings (HtmlAnchor) are referenced on some other page, it would be impossible to delete it without removing the references. That would make anchor links always be consistent and referable.
Possible workflow: An editor opens the page property view and presses the + sign on the "HtmlAnchors" property. Adds the string "detailed-overview". A front-ender working with code would then add something like that to the page template:
<h4 name=#Model.Anchors("detailed-overview")>Overview</h4>, and in referring pages use the (as of yet non-existing) url helper #Url.PageLinkWithAnchor(Model.PageLink, "detailed-overview") to create a link to that anchor.
If using a wysiwyg editor then it could use IAnchorPage#Anchors() to list the existing anchors and IAnchorPage#AddAnchor() to add an anchor.
Of course, I see how what I sketched out above seems to rest on a shaky foundation, as it uses simple strings ... which might not really add much else than overhead.

Custom Node type CSS, best place to put it in Drupal 7

I'm building a Drupal 7 type that has two distinct types of page, public ones and ones only shown to authenticated users, with entirely different templates. The choice of which template to use is done in the theme preprocess function.
Each of the two main templates has its own CSS, which needs to be placed in the header in the right place relative to the theme and base CSS. What is the best place to include these CSS files?
I can't add these sheets to the theme .info file, since those are applied to all templates. At the moment I am adding them in the theme preprocess function, but it seems like needless complexity, since the stylesheets are essentially static (all pages with the same template have the same 3 sheets). On the other hand hard-coding them in the template file (e.g. after the normal print $styles) seems like it is "not the drupal way" (tm), and also won't take advantage of CSS compression and caching.
So what is the right way?
you have no best place to insert your css file. You can just use drupal_add_css() anywhere you want. The css will be anyway write in the header.

Managing dynamic, responsive content at the backend in Silverstripe

I am currently trying to jazz up a SilverStripe site by making the content more engaging. The site is responsive, but all this means currently is that the navigation bar/header snaps to a more mobile friendly style when it hits the mobile break point.
The long and short of it is, my main page.ss is this:
<html>
<head>
<title>$Title</title>
</head>
<body>
$Header
$Layout
$Footer
</body>
</html>
With $Layout rendering a few variations of a basic page. We have a couple of layouts that aim to give our webmaster pages that are a bit more engaging - for example we have an accordion type page that has many accordion section DataObjects, that present the page as an accordion page with the open/shut javascript functionality.
But this is not enough. I want to give the webmaster more flexibility in the CMS to create interesting pages, without me having to create hundreds of different page types.
I'm thinking of creating a module that gets rid of the main $Content field for all pages, and instead inserts a sort of grid system management field. The webmaster can add rows (one DataObject) and then split those rows into sections (another DataObject). The sections will have a content field managed by TinyMCE, just like a page has. Then on the front end I will map these rows and sections to a responsive grid system.
For variations on the sections, I will add classes (a bit like having different page types) that render slightly differently. The sections will have .ss and .css (and possibly .js) to control their own look and feel.
My question is, how have other people approached this problem? Does my idea sound like overkill? Or does it sound like a good idea for a module?
-
For some examples of what I am trying to achieve, this page is a good example:
http://www.wingsforlife.com/en/research/
Content is split up into various sections, which allows for better control when the page is resized. Also throughout the site, content is varied, sometimes it will be in a single column, other times two, which snaps to one column when the window is smaller.
On the home page, if you scroll down, there are 4 links that are presented inside circles, that contain a number and some text: http://www.wingsforlife.com/en/
This is something I can't see being possible inside TinyMCE (which is fair enough as TinyMCE is just a basic content editor, not a web design tool).
Have a look at https://github.com/burnbright/silverstripe-widgetpages for an implementation of using Widgets to compose a webpage. Also https://github.com/g4b0/silverstripe-widget-pages-extension.
this can easily be achieved by replacing the HTMLEditorField that's linked to the Content field in the database by some GridField, managing DataObjects that make up what you might call 'ContentParts'. we've already used this approach in some projects to allow for more rendering flexibility of content elements.
simply tie some DataObjects to your Page class:
private static $has_many = array(
'ContentParts' => 'ContentPart'
);
then, use a GridField to manage them in your getCMSFields:
$gridFieldConfig = GridFieldConfig_RecordEditor::create();
$field_ContentParts = new GridField('ContentParts', 'Content Parts', $this->ContentParts(), $gridFieldConfig);
simplest way to render them in your template is as follows:
<% loop ContentParts %>
<section>...</section>
<% end_loop %>
of course you'll want to have different contentparts, so you might want to create subclasses of ContentPart with their custom fields and use the GridFieldAddNewMultiClass component to add them to your GridField (it's part of the GridFieldExtensions module, to be found here: https://github.com/ajshort/silverstripe-gridfieldextensions)
hth

Drupal taxonomy views override path for specific content

I am beginning to be a little desperate here. I have following structure (Drupal 7):
I use taxonomy menu to build menu links,
The taxonomy_term default (page) view is used to override drupal's taxonomy/term/% path
In addition to it I use menu_block module (but I doubt that this is important). What I am trying to achieve:
I need to build node browser by category (taxonomy term) but it has exceptions - for example taxonomy term with id 850 (taxonomy/term/850) must have different content structure than other therms. Is it possible to override default views display with these exceptions? I tryied to create another display with this path but the result was "not found". I also thought on using blocks not page displays, yet this solutions does not seem to be the Drupal way to me.
I was facing the same problem while trying to have different display/structure for publications in contrast to normal articles.
What I did, created a separate view for that specific taxonomy such as taxonomy/term/850, and in the path in view I entered 'taxonomy/term/850' (in this case)
This caused it override taxonomy/term/%
and displayed it differently according to my need.

What is the best way to create regions in your CakePHP layout similar to WordPress Widgets or Drupal Blocks?

What is the best way to create regions in your layout similar to Wordpress's Widgets or Drupal Blocks? What is the best practice method of doing that in CakePHP?
If by regions you mean a special "content container" (never used WP/Drupal), then it's very easy.
There are several ways to accomplish this, but the one that came to my mind first was this:
Create a helper (or an entire plugin) to handle the "which content goes into which container" logic. Shouldn't be too hard to do because you have many Cake utility classes to help you out with that (such as the Configure class). This should obviously be configurable by the end user.
Create containers in your layout, example:
<div class="content-container" id="content-container-left">
<?php echo $yourHelper->outputContent("left"); ?>
</div>
Two options:
Content should be based on elements; or
Content should be based on custom plugins (which actually do their stuff and output the content)
Note: There are probably better ways to accomplish what you want, this is just the first that came to my mind. I'd recommend some pencil-and-paper planning before you actually code anything, it will improve your chances of finding the best way for your app.
I created a Sidebar Helper recently that you might find useful.
You define the content of the boxes in Cake elements, and then add them by calling ...
$sidebar->addBox(array('element'=>'my_sidebox_element');
... this would render the content of views/elements/my_sidebox_element
Alternatively you can specify te content of a box 'inline':
$sidebar->startBox(array('title' => 'My Inline Box'));
<p>blah <b>blah</b> <span>blah</span></p>
$sidebar->endBox();
The in your layout file call
echo $sidebar->getSidebar();
... and each of your boxes will be rendered as divs
Technically speaking this doesn't need to be used as a 'SideBar' - it ultimately depends on how you render the layout with CSS.
See the documented code for more details:
SidebarHelper on GitHub

Resources