Hello community – I’m building a website that has a container inside, and is filled with contents via click. The content comes from a jquery .load(url) call.
With this function I call a template, which is missing header and footer snippet, called project.
I don’t want to load header and footer, because it is already in my home.php, the site with the container.
The URL has to change as well. I do this with window.history.pushState(id, id, url); so if some one is sharing the page with the content, the entire site will be displayed, and the content will be loaded inside the div. There is also a close button, that deletes the url uid and deletes the contents.
Now my problem is, that if I open the website with a subdomain, the header and footer will not be loaded, because it is missing in the project.php template. I did this before with an AJAX call, where I could detect it and load header and footer with the project template.
Now I was looking for solutions and came across Content Representations, but I don’t really get it.
My approach would be to have an projects.json.php file, where I store all project information. But I’m not getting smarter. I only want to load header and footer when a subdomain gets shared and opened. I detect the subdomain via
window.onload = function () {
console.log('new');
var url = window.location.href;
url = url.split("/");
if (url[4] == 'projects'){
console.log('in projects');
}
}
And the most primitive way is to redirect to the homepage, look for the uri that is stored in the url, and make an artificial click. But there must be another way.
You can load the normal template (=standard URL projects) with header and footer for the subfolder page, and the the JSON representation (projects.json) without header and footer when you load the content into the home page.
Depends on what your content representation returns, that’s up to you to make it return the data you need. If you want to filter data, you can do that.
True, but my question is if I can take the clicked element (in projects) and look for its subfolders (project) content. I’m not sure how to filter it, do I take the uri from the clicked element and put it in the fetch function? I think this is missing in the cookbook generating-json
If you click a link, you have a href attribute, or if you are using a button, you can use a data attribute with the project ID or URL. In your JS, you fetch this attribute value and take it from there.
One thing that kept me awake this night:
I could also just use the .load() function with the specific URL and look for the content in the project and ignore header and footer snippets. Therefore a JSON is not required, or does it?