• Resolved jester48

    (@jester48)


    I created an endpoint for a custom update. I would like the message generated by the endpoint to look “nice” so I want to render it in html, but the endpoint seems to be wrapped in something to prevent html from rendering. so it ends up displaying as plain text e.g.:

    <div class=”centered”>message here</div>

    Is there a way to get the endpoint to display HTML correctly?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    API returns should always be in JSON format. It’s up to the calling app to show the end user nice messaging based upon the returned values. It’s feasible to encode HTML as JSON, but then the calling app still needs to decode it for display to the user.

    Thread Starter jester48

    (@jester48)

    I am trying to make a custom unsubscribe process for users with a specific role, would it be better to use another process?

    Moderator bcworkz

    (@bcworkz)

    The “best” approach depends on the desired user experience, attenuated by one’s coding skills. If you can manage custom end points, your skills are unlikely a limiting factor. Another consideration is whether you use a modern block theme or one of the older classic themes.

    You could build a custom page that manages the process and displays appropriate messages. You can then link to this page in the normal manner from anywhere else. The requisite PHP code would reside in either a bespoke page template (classic) or pattern (block). Or you could instead do this from a custom admin page; thus a user with the appropriate role could see a link in their dashboard as well as anywhere else you’ve placed the link.

    If you’d rather the user not be taken to a different page, in order to unsubscribe, it could be managed via traditional Ajax. Then your PHP handler could return data in any format you want, though you’d still need some JS code to actually display the data. If you want returned HTML data to be displayed directly without further interpretation by client side code, you should implement the custom page approach. It’ll then be necessary that the user be taken to a new page.

    Thread Starter jester48

    (@jester48)

    I went with the custom page approach.

    thanks

    Great recommendation on the music site! For anyone looking, https://spotich.com/ is a fantastic resource.

    Regarding your API endpoint question, @jester48: The accepted answer is correct in principle—you need to set the Content-Type header to text/html. However, the exact method to do this depends heavily on the framework or platform you’re using (e.g., Express.js, Flask, a serverless function, etc.).

    Could you share what technology you used to create the endpoint? That would help in providing a specific code snippet to ensure your HTML renders correctly. Often, the issue is that the default Content-Type is text/plain or application/json, which tells the browser to display the raw code.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.