I'm trying to add code examples to a custom template. I am creating a php example but it isn't rendering properly in the portal. I am doing
<pre> <code> <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://urlpath", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Content-Type: {value}" ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if($err){ echo "cURL Error #:" . $err; } else{ echo $response; } ?> </code> </pre>
However it is getting rendered like:
<pre> <code> <!--?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL =>--> == $0 "https://urlpath", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Content-Type: {value}" ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if($err){ echo "cURL Error #:" . $err; } else{ echo $response; } ?> </code> </pre>
Is it interpreting the php tag? is there a way to prevent it from doing this?
Solved! Go to Solution.
I solved it by using & l t ;?php(no spaces) instead of <?php
I solved it by using & l t ;?php(no spaces) instead of <?php
@daniel.biales , Thank you for sharing with community, I strongly believe having these snippets in the smatdoc template is a maintenance nightmare.
I am working on a solution that will help easily maintain code samples associated with a particular Smartdoc using Drupal CMS out of the box featuers. I will keep you posted with updates once i have the working solution.
Would that be a manual process performed by the admin or part of the swagger upload process?
@daniel.biales , I don't think swagger / OpenAPI spec supports code samples, I am planning to do them manual but configurable elements in the CMS using admin screens instead of hardcoded values inside the template.
Why do you think its a nightmare? If the code samples were part of the swagger upload process that would be nice.
Swagger custom extensions are not supported in smartdocs as far as i know, so, option is ruled out at this point of time. I am planning to do them manual but configurable elements in the CMS using admin screens instead of hardcoded values inside the template.
Ok I don't think that will work for us because we built a tool that allows non admins to upload and publish smartdocs via an API, so they would not have admin privileges to create code examples. However, that does seem like a good feature.