I have a custom blog template being applied across several blogs in the store w/ several tags for each blog. My code grabs the pathname and splits it to determine which of several custom hero sections to load. I’m trying to get the custom Hero to load even if there are no articles for that tag. But in the console the GET request 404s
GET https://{www.domain.com}/blogs/{blog-name}/tagged/{tag}?view={template-name} 404
Which in turn causes my 404 template to load instead.
This issue doesn’t seem to be happened on the first tag in my switch statement. It loads the hero and my articles section is empty, as expected. I don’t even get the 404 back in the console.
Variables:
const pathName = window.location.pathname;
let blog_div = document.getElementById('blog-hero');
const blogName = pathName.split('/')[2];
const tagName = pathName.split('/')[4];;
let return_div = String;
Switching on blog, sending to switch function to switch on tag:
const blogFunction = (blogName) => {
switch(blogName) {
case 'blog1':
function_blog1(tagName);
break;
case 'blog2':
function_blog2(tagName);
break;
}
}
Switching on tag and returning section string:
const function_blog1 = (tagName) => {
switch (tagName) {
case 'tag1':
return return_div = `{% section 'blog--hero-blog1--tag1'%}`;
break;
case 'tag2':
return return_div = `{% section 'blog--hero-blog1--tag2'%}`;
break;
}
}
Then I call the blogFunction and pass the tagName. Then assign return_div to innerHTML of my div.
blogFunction(blogName);
blog_div.innerHTML = return_div;
I’m thinking since I have the first tag loading even it is empty but not the other the issue may be in my switch statement?
Separately, I’m looking at how to make the code more dynamic so I don’t have to hard code the blog names and tags. Liquid isn’t allowing me to interpolate those variables. And it’s making my code too large. This is the more pressing issue but perhaps they’re related.
Any ideas?
EDIT 1:
Tried to console.log from each case prior to my return statement and the first case will return the console.log but the 2nd one won’t. So it’s not even going into subsequent cases, hmmm.