Composite C1 - Show different content in Page Template Feature, depending on domain - c1-cms

I have a C1 CMS with 5 domains / sites in it.
I need a Page Template Feature to display different content depending on which site it's on. Or perhaps have a page template embed a different Page Template Feature depending which site it's on.
One way would be to use the domain of the site to differentiate somehow (I don't know how). Are there any other ways to do this - what would be best?
Thanks.

I simply put razor code like this in the MasterLayout.cshtml page to display the appropriate Page Template Feature, depending on the domain:
#{
if (Request.Url.ToString() == "http://Domain1.com")
{
#PageTemplateFeature("Footer Domain1.com Front Page")
}
else if (Request.Url.ToString() == "http://Domain2.com")
{
#PageTemplateFeature("Footer Domain2.com Front Page")
}
else
{
#PageTemplateFeature("Footer All Other")
}
}
It is a shame there isn't a way of doing this within the C1 CMS itself - but this works fine.

Related

ExtJs View with multiple style (scss) for each language

My ExtJs application has to be multilingual.
On the login page, I asked the user to select the language from a dropdown list.
the current structure of my application files as the following
[app]
[classic]
[src]
[view]
[customers]
customerController.js
customerView.js
customerView.scss
How can I have multiple scss files for the same view ?
For example customerView.scss to be a general file loaded all the time, customerView.en.scss to be English specific, only when the user selects English on the login page, and customerView.es.scss only when the user selects Spanish on the login page
Or is there any better idea?
The easeiest way might be to add a class to the viewport:
Ext.getBody().addCls('language-en')
Inside your scss files you add:
.language-en {
.customer-view {
}
}
.language-de {
.customer-view {
}
}
Otherwise you have to get into the build.xml and into the fashion builder.
In the fashion builder you have to rearrange the build.

Change where a Page is displayed in the URL

I have setup my website whereby the main parental/tree structure is Home > Shop > Category > Product" with > denoting parent of.
This works fine, however when accessing a Product(Page) the url is automatically (and correctly) configured at /shop/test-category/test-product by Wagtail.
I would like to change it so that the product is actually displayed as being at the root level (even though it isn't). So if a user accesses Test Product it would be at /test-product/.
Looking through the docs, the RoutablePageMixin seems like it might do the trick but I have no idea how to go about implementing it. Any ideas?
This solution will make the product available at both URLS:
/shop/test-category/test-product/
/test-product/
Approach:
You are correct that you will need to use RoutablePageMixin, be sure to install it in your installed_apps as per the instructions before importing.
The example below adds RoutablePageMixin to your HomePage, as this is the page that will be located at the root / URL. We do a regex check and match for a single slug before a trailing /.
Then we see if we can find a ProductPage with that slug, and serve (or redirect) to that page. Finally, if there is no match, we call the home_page's serve method with the current request to handle anything else. This may be an incorrect URL or a correct sub-page URL.
Caveats:
If you have a sub-page at the same slug as a product page, the sub-page will never load, there are no smarts in this code to work around that. You could put some logic in the validation of product names and sub-page names if this becomes an issue in the future.
This does not consider SEO issues, search engines will treat these as different pages and hence you may want to think about declaring your canonical URL in your meta tags.
This does not redirect back from /shop/test-category/test-product/ to /test-product/ - that can be done by overriding the serve method on your ProductPage and redirecting to something like home_page.url + '/' + self.slug.
Example Code:
# models.py - assuming all your models are in one file
from django.db import models
from django.shortcuts import redirect # only needed if redirecting
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
from wagtail.core.models import Page
class ProductPage(Page):
price = models.DecimalField(max_digits=5, decimal_places=2)
content_panels = Page.content_panels + [
FieldPanel('price')
]
class HomePage(RoutablePageMixin, Page):
#route(r'^(?P<product_slug>[\w-]+)/$')
def default_view(self, request, product_slug=None):
"""Route will match any `my-product-slug/` after homepage route."""
product_page = Page.objects.exact_type(ProductPage).filter(slug=product_slug).first()
if product_page:
# option 1 - redirect to the product's normal URL (non-permanent redirect)
# return redirect(product_page.specific.url)
# option 2 - render the product page at this URL (no redirect)
return product_page.specific.serve(request)
else:
# process to normal handling of request so correct sub-pages work
return self.serve(request)

Drupal 7 Maintenance Mode Custom Page Not working

Prelude
Drupal 7
Bootstrap Business (Active Theme)
Turn on Maintenance Mode
Actions that I have already carried out
Copy maintenance-page.tpl.php from modules/system/maintenance-page.tpl.php
Edit to your needs
Paste it on theme's root folder --> /public_html/sites/all/themes/bootstrap-business
Set $conf variable in /public_html/sites/default/settings.php : $conf['maintenance_theme'] = 'bootstrap_business';`
Nonetheless, the site keeps on showing the modules/system/maintenance-page.tpl.php . I don't know why it is not working. I´ve also tried:
Adding a maintenance-page--offline.page.tpl.php
Setting the theme name as bootstrap-business
None of the above work. I don't think spending 45 minutes on such a simple task is adequate. I know I could just edit the modules/system/maintenance-page.tpl.php, but I don´t believe that's the right way to go.
Any suggestions?
Clear/Flush caches (Theme Registry cache) and try again. If you already did that and did not work add a page preprocess function to your default theme template.php:
bootstrap_business_preprocess_maintenance_page(&$variables) {
if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
// Template suggestion for offline site
$variables['theme_hook_suggestion'] = 'maintenance_page__offline';
}
else {
// Template suggestion for live site (in maintenance mode)
$variables['theme_hook_suggestion'] = 'maintenance_page';
}
}
Related question: https://drupal.stackexchange.com/q/76946/12163

Nginx config for serving snapshots to the Google bot

I have an AngularJS app which I'd like to get indexed properly on Google.
I wrote a client that scrapes the sites for links and then downloads the pages with Phantomjs making snapshots. This all works fine. What I'm having a problem with is serving those snapshots to the Google bot.
For some reason, the Google bot appends ?_escaped_fragment= to my URLs. As an example, http://me.com/about gets changed to http://me.com/about?_escaped_fragment=. I've verified this in the access logs.
I'm trying to catch this request and serve the Google bot the snapshot with this config:
location / {
if ($args ~ "_escaped_fragment_=") {
rewrite ^ /snapshots/$1;
}
}
However, requesting this URL: http://me.com/about?_escaped_fragment= always results in a 404. Same with the other pages.
The snapshots are stored in /snapshots, relative to the root of the website. They're named after their pages, following directory structure, so http://me.com/business/register has a snapshot in /snapshots/business/register.html.
What can I do to get these snapshots to work?
Thanks.
Ok first let me explain why google uses ?_escaped_fragment_, This is used for websites that rely on ajax, and mark their page with hashes, like for example if you have http://example.com/gallery/#!image1 and each time the user changes to the next image you update the hash to image2, image3, but if the user goes directly to http://example.com/gallery/#!image50 your javascript uses that hash to load the 50th image directly instead of image1 ( servers can't see the hash part, only javascript can ).
So google uses this _excaped_fragment_ to tell the server which page it's trying to cache.
For more explanation use this link
As for why you get a 404 error, I think because you used a $1 without using a capturing block, The right rule would be something like this
location / {
if ($args ~ "_escaped_fragment_=(.*)") {
rewrite ^ /snapshots/$1;
}
}
But I don't think this will fix your problem, because according to your example, you didn't use hashes, you used the uri of the page, so i would rewrite the rule to something like this
location / {
# try snapshot, if not found try direct file.
try_files snapshots$request_uri.html $uri;
}
Here is what I have in nginx and it is working fine, you might need to add a special one for index.html (i.e. when accessing the root of your website)
if ($args ~ "_escaped_fragment_=/(.+)/?") {
set $path $1;
rewrite ^ /snapshots/$path.html;
break;
}
location /snapshots/ {
internal;
alias /var/www/snapshots/;
}
So http://me.com/?_escaped_fragment_=/about will access /var/www/snaphots/about.html
Don't forget this meta tag as well in your page if you use html pushstate instead of hashbangs:
meta(name="fragment", content="!")

Email template not using themed version

I am using CakePHP 1.3 and the built in email features as described in the documentation. I have the html version of the template located in app/views/elements/email/html/reservation.ctp and its working as expected.
$this->Email->template = 'reservation'; // no '.ctp'
I also have a theme setup and most of the themed files are correctly overriding the default files. My problem is the themed email template is not being used when called from the themed site, its still using the email template file in the default path.
The default is at: app/views/elements/email/html/reservation.ctp
The theme is at: app/views/themed/myTheme/elements/email/html/reservation.ctp
Should the email template assignment automatically work with themes without the need for hard coding a path or is there another solution? Anyone else have this issue?
in cakephp when you want to create email template. Lets suppose we want to create an Html email. and email config is configured.
Views[File Structure]:
1) your content email with variables should be located in View/Emails/html [reservation.ctp]
2) your template should be located in View/Layouts/Emails/html [default.ctp OR any new template you have made]
controllers:
Note: some people think when you write an action(in controller) you have to write a view for it. In this case (for sending email) is completely wrong. only if you want to show the result which email sent successfully or not then is fine.
lets say ReserveController ;) and sendReservationEmail
function sendReservationEmail( $to, $from,$subject ,$template, $variables=array()){
$Email = new CakeEmail();
$Email->config('smtp')
->viewVars($variables)
->emailFormat('html')
->template($template['page'], $template['layout']) //'reservation', 'default'
->from($from) //'me#example.com' => 'My Site'
->to($to) //'you#example.com'
->subject($subject) //'Resevation'
->send();
}
Views (View/Emails/html/reservation.ctp):
Dear $this->viewVars['name'];
Welcome to our restaurant .....

Resources