427 votes
1 answers
javascript - Conversion Uppercase in .liquid
Solution:
If I understand well, author var is encoded with caps in Liquid data source.
I'd say something like that should work (not tested):
{% liquid
assign author = article.author | downcase
assign author_parts = author | split:' '
for part in author_parts
echo part | capitalize | append: ' '
endfor
%}
Undefined asked
602
votes
Answer
Solution:
You never update the actual element contents:
<script> var span = document.getElementById("blog_author").innerText.toLowerCase().replace(/\b(\w)/g, x => x.toUpperCase()); console.log(span); </script>
The code above takes the contents of#blog_author
. The text (not the element) is then modified and stored in thespan
variable, but the text contents of#blog_author
is never updated.
To solve this issue you should reassign the text to the element.
<script>
const elmBlogAuthor = document.getElementById("blogAuthor");
const oldName = elmBlogAuthor.innerText;
const newName = oldName.toLowerCase().replace(/\b\w/g, chr => chr.toUpperCase());
elmBlogAuthor.innerText = newName; // update the element contents
console.log(oldName, "->", newName);
</script>
Undefined answered
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.