I’m building a module to add some metatag for seo purpose, like google webmaster tools verification metatag.
I need to put this metatag only on homepage. I have created the module with an interceptor that add this on cbui_beforeHeadEnd. However this will show the meta on all pages of the site.
Is there a method to put this content only on homepage?
My method may not be the best method for this, but I’ve been using a custom layout for my homepage screen vs. the page.
/layouts/home.cfm
/layouts/page.cfm
Then on my main page in the Administrator, I’ve linked that page to my home layout vs. page layout for other pages. This allows me to do whatever customizations directly in the template instead of the handler for the homepage.
It sounds like you have hard coded your changes into the system, this is certainly not the best approach at all.
Too add any meta tag information, you need to look into using interceptors and how to create a module, I have many blog articles on this that will help get you started as well as a list of connect session on the ContentBox website as well as ColdBox as it is written using ColdBox.
If you are hacking like this, you are only opening yourself up to further heartache and frustration when things don’t work and low and behold you will also find getting help harder because you haven’t bothered to take the time to do the job correctly. If you need help and a pointer then we can help there, but not when we get a question like this.
Or you could look into the option in the Admin Dashboard where you can add information to the header etc, and add it there, this will become global to any layout theme your using and I would advise not to go this route if you don’t want it in all themes.
I’m familiar with interceptors and how to create modules, but I threw my solution out there (however bad the solution was) because I’m learning about themes / layouts and I recently had an occasion in which I really needed lots’ of customization in the view for the homepage vs. any other page in the site. So there is where my response to the actual question came from. You are right however, it is probably not the correct or best approach for his specific need.
The original question came from Francesco Pepe, whom still is looking for an answer. While I don’t know the best practice or technique here, it wouldn’t hurt to post a link or two to one of those blog posts that would steer this guy in the right direction.
This shows how to hook into one of the Entry Interception points, it could easily be modified to hook into any of the header or body Interception Points.
However there is one thing one needs to take into consideration when doing anything with Google+ Authorship. ContentBox sends an incorrect header response for anything that is cached. Google+ doesn’t like this and one will have to modify ContentBox for Google+
Which looks like it will be released as part of ContentBox V2.0, so in the meantime one is going to have to manually patch the code to the blog post I provided above.
I’m familiar with interceptors and how to create modules, but I threw my solution out there (however bad the solution was) because I’m learning about themes / layouts and I recently had an occasion in which I really needed lots’ of customization in the view for the homepage vs. any other page in the site. So there is where my response to the actual question came from. You are right however, it is probably not the correct or best approach for his specific need.
The original question came from Francesco Pepe, whom still is looking for an answer. While I don’t know the best practice or technique here, it wouldn’t hurt to post a link or two to one of those blog posts that would steer this guy in the right direction.
Well said Brad, I didn’t mean to come across as it is not a good idea. I just think Hard coding things like this is just not the right way for obvious reasons.
I know it is hard to grasp the concept of what and how themes (layouts, I hate the term layout in ContentBox as it is a theme anyway) actually work and knowing what and where and how to do something is not easy to find at the moment.
So, the reply to the post is that is not possible to add a metatag only to homepage? I use interceptor, but it will be fired on every page. Not a great problem in my case, but seems this is a missing feature. However I will post code to my module as soon as it’s possible to show what I’mtrying to do.
There are a number of things you can do, but the most easy is to do something like this if it is never likely to change.
public void function cbui_beforeHeadEnd() event=“please past event here” {
}
So if the home page is the default ContentBox, it will be contentbox-ui:blog.index, if in your case it is to a particular page then you would do something along the lines of contentbox-ui:page.slugname or something like that, you may need to search the code for the right event.
Now if the page is likely to change, then the same rule sort of applies, you would write something like this.
public void function cbui_beforeHeadEnd() event=“contentbox-ui” {
}
This will ensure that the interceptor is only run for the front end, or if you could add the page to make it.
public void function cbui_beforeHeadEnd() event=“contentbox-ui:page” {
}
Which ensures that the interceptor will only run when the page is called. Then you could do the slug check etc with in the body of the function. And if it is only the default home page, the event would something like mentioned above with blog.index.
Or you could then just change the event to use the UI, then check the URL inside the method.
First the cbhelper, is the other option I was trying to think of and not being near a computer with ContentBox installed had to go by memory. But the checks are cheaper with the eventPattern as it is not reliant on calling the DB for no reason. Just something to consider there. The best option is to actually check for the eventPattern so that no other code is run unnecessarily.
The interception point for cbui_onIndex is another point to consider, however the only drawback with this is that the data is not added to the header, which can be very important for SEO stuff.