How to include Article in Multiple Sections

22 Comentarios

  • Andrei Kamarouski

    Great tip, thx! 

    1
  • Alejandro Colon

    Andrei Kamarouski

    I have many more tips to come but this seemed particularly useful. 

    2
  • Andrei Kamarouski

    Alejandro Colon, can't wait to read them =) 

    0
  • Brett Bowser
    Zendesk Community Team

    Awesome tip Alejandro! We will get this added to our weekly digest so others can take a look :)

    0
  • Alejandro Colon

    Brett Bowser

    I think I have made it into one of those before. :)

    -----------------------------------------------------------------------------------------------------------

    Andrei Kamarouski

    Here is a link to some of the tips I plan on writing up. 

    Ranking Tips to be written up

    I am looking for some feedback on what users would like me to write up first. 

    My original list had no preference on which I would write up first. Just a list off the top of my head. 

    0
  • Chloé Mauduit

    Hi Alejandro,

    I tried to implement this great tip but it does not work for me...

    If I understood correctly: for eg I have one article appearing in 2 sections: Section A and Section B. 

    I create a first article called Hello and publish it in Section A. I create then a second article called also Hello but this time in Section B. I copy the article ID of the 1st article created in section A and copy this ID in the labels of the second article in section B. 

    Now if I update the article in section A, the article in section B will automatically be updated. And same for the other way around.

    Is this correct? 

    Thank you in advance,

    Chloé

     

    0
  • Alejandro Colon

    Chloé Mauduit

    Sorry for the late response. 

    --------

    This workaround does not replicate or duplicate any information. What it does is actually redirects the user when they click on a duplicate article. 

    In your example, you took the article ID of Hello in Section A and added it as a label to the duplicate article in Section B. Assuming all of the code is working correctly, then this would cause any user that goes to the article in Section B to automatically be redirected to the article in Section A. 

    This allows you to only have to edit the article in Section A, as all users will be redirected to that article instead of the duplicate articles. You can almost think of them as placeholders. Any text you put in the article in Section B will not be doing anything as the user will have been redirected with the redirect label you used. 

    ------

    Sorry if this is a bit confusing but I will answer any questions you may have to the best of my abilities. 

    1
  • Chloé Mauduit

    Hi Alejandro,

    Thank you for your reply.

    I do have one question: When I create the 2nd article in section B, do I still need to copy the content? Or only enter the ID article in the label?

    Thanks in advance,

    Chloé

    0
  • Alejandro Colon

    You do not have to copy the content. 

    ----

    But, what I do, to cover my bases is write a boilerplate message, something like this:

    "This article is a duplicate. The original article is http://(companyID).zendesk.com/hc/en-us/articles/(articleID)"

    That way if for whatever reason the redirect does not work, the user will still be able to get to the content.

    0
  • Chloé Mauduit

    Hi Alejandro,

    Thanks for your quick reply. I tried again but it seems to do not work still.. 

    I entered a label= article id number.

    Do you have to enter the javascript and htlm codes on a specific line/section in the article_page.hbs or script.js?

    Thanks again,

    Chloé

    0
  • Alejandro Colon

    Chloé Mauduit

    You should not have to place the code on a specific line/section in the file. 

    That being said, I put the code for the article_page.hbs at the very top. Make sure you are not putting the code inside another code block. This could stop the code from working.

    Thankfully, I have included some console logging so that should help us diagnose what is going on. Open any article and pull up the console (usually the console can be opened with control + shift + i) and see if something along the lines of the following is visible:

    This will tell us if the code for adding the labels to the article is working or not. 

    --------

    If you can please provide copies of your entire article_page.hbs and the script.js that should help as well. 

    -------

    Also, if you do not mind, send me a link to your Help Center and I can check that the JS is working correctly as well. 

    0
  • Chloé Mauduit

    Hi Alejandro,

    Thanks for your quick reply.

    I have tried to follow every steps and tips you gave me but it still does not work...

    Here are my Javascript and article page codes:

    And here is the link of our Help Centre: link.

    Thank you very much for your support,

    Chloé

    0
  • Alejandro Colon

    I am taking a look at your HC and it looks to be set up correctly. 

    I can see that the article page script is working as the console logs are showing up. 

    ---------

    Let's confirm a few things:

    I went to this article and the labels shown in the console logs are "Roadmap to Zero Programme", "Input", "MRSL", "Candidate", "List". Is this correct for that article?

    Can you give me a link to an article that should be redirecting but is not?

    0
  • Chloé Mauduit

    Yes I confirm that this article has those 5 labels assigned.

    Here is one article that should be redirected but is not: https://knowledge-base.roadmaptozero.com/hc/en-gb/articles/360010748977-Registering-on-the-ZDHC-Gateway-Frequently-asked-questions

    Thank you!

    Chloé

    0
  • Alejandro Colon

    I have figured out the problem but I am still trying to figure out how to fix it for you.

    For some reason, your script.js is running before the content starts to load. The content loading is where the labels are added to a variable. The script then checks that variable and does the redirecting. 

    Because the script.js is checking the variable before it is set, this means that it always believes that there are no labels. 

    I am thinking of a modification to my original script to see if I can fix this for you.

    0
  • Alejandro Colon

    I have adjusted the code to fix the issue of the script.js running before the article_page.hbs ran.

    Instead of splitting the code between the two, I have implemented all of it in the article_page.hbs. Now there is no way for the redirect portion of the script to run before the "labels" variable is populated. 

    I have updated all of the above documentation. 

    Give that a try for me. 

    Also, remember to remove the code from the script.js as it would be duplicated if not. In your case, this wouldn't cause a problem but it is best practice to remove unused code. 

    1
  • Chloé Mauduit

    Hi Alejandro,

    Thank you so much, it works perfectly now!! Huge thanks!!

    Chloé

    0
  • Alejandro Colon

    Chloé

    You are absolutely welcome. 

    --------------

    This version of the code is actually better as it consolidates the code and will not run unless it is an article page. 

    --------------

    Let me know if you have any other trouble. Have a great weekend! :)

    0
  • Ronald Devine

    Hello Alejandro,

    Thank you for this creative idea. Seems to be working fine for me so far.

    I have a a question. I have a knowledge base in 4 other languages besides English.

    How would I extend your code for those other languages?

    Is it as easy as just adding an additional line of code for each language one after another?

    Or is there more work to it?

    ex.. 

    window.location.href = 'https://(yoursubdomain).zendesk.com/hc/en-us/articles/' + labels[i];
    window.location.href = 'https://(yoursubdomain).zendesk.com/hc/fr/articles/' + labels[i];
    window.location.href = 'https://(yoursubdomain).zendesk.com/hc/de/articles/' + labels[i];

     

    0
  • Alejandro Colon

    Ronald Devine

    Sorry, it took me so long to respond.

    I was not taking into consideration multiple languages when I made the code. I am updating the code to work with multiple languages and removes the need to specify the subdomain.

    Code to Replace

    window.location.href = 'https://identityfusion.zendesk.com/hc/en-us/articles/' + labels[i]; 

    Code to Replace with

    // grabs the url and removes the extraneous information
    var baseurl = window.location.href.match(/^([\w/:.]*)([/])([hc]+)([/])([\w-]*)/g);

    // some logging for debugging
    console.log(baseurl + '/articles/' + labels[i]);

    // changes the page to the baseurl + article section + the article ID
    window.location.href = baseurl + '/articles/' + labels[i];

    The new code grabs the current URL, including the language portion, then removes the extraneous part to create a baseURL, then adds the article section, and the article ID.

    I added some logging for debugging just incase.

     

    Give that a try for me.

    My org does not have multiple languages so it is a little harder to test but that should work for you. 

    1
  • Stephen Hallsworth

    Thanks for the code - very useful feature.

    However, the amended code shown above doesn't work - it is missing a } , just before the </script>.

    0
  • Alejandro Colon

    @Stephen Hallsworth

    Thanks for letting me know. 

    I adjusted the code to include the missing bracket.

    Thankfully, the photos are correct as I simply missed it when copying it.

    0

Iniciar sesión para dejar un comentario.

Tecnología de Zendesk