Cannot succeed to use Inline sample (JSON)
kevung opened this issue · 10 comments
Hello,
According to https://sphinxcontribdatatemplates.readthedocs.io/en/latest/inline.html
it is possible to use inline sample (JSON), without the use of templates. I cannot succeed to use it.
I have the same folder :
- rst file
test.rst
Test
=====
.. datatemplate:json::
:source: test.json
{{ data['allo'] }}
- json file
test.json
{
"allo": "kiki"
}
When I build the Sphinx documentation, I get no error but the corresponding page show {{ data[“allo”] }}
instead of kiki
the actual value.
I understand this behavior since Sphinx has no way to know the difference between regular rst text and template instructions.
I confirm that I can use without problem JSON Samples with templates with this Rst file and a template:
Test
=====
.. datatemplate:json:: test.json
:template: test.tmpl
My use case for using the inline sample (JSON) is to extract specific key/value from a single JSON database (and I would have to create a template for each specific case otherwise with the JSON sample+template ).
But maybe I am using the extension with the wrong state of mind... and it is not conceived to have a central JSON/CSV database, but multiple JSON files for each Rst file. Since and I would like to use JSON really like a database (when I make a change to the latter, I want the change to be propagated in all Rst files), that would be not practical for me.
In the documentation, https://sphinxcontribdatatemplates.readthedocs.io/en/latest/inline.html
the template is indicated to be inline but there is also a section for loading it. I am a bit confused.
I think the problem is with indentation. The template body needs to be indented under the datatemplate
directive. You said you have this:
- rst file
test.rst
Test ===== .. datatemplate:json:: :source: test.json {{ data['allo'] }}
But I think you want this:
Test
=====
.. datatemplate:json::
:source: test.json
{{ data['allo'] }}
I changed the :source:
line and the {{ data['allo'] }}
line so they both have 3 spaces at the front.
Bravo ! This solved my problem. Thanks so much.
If I may suggest, perhaps the "Template File" section in the documentation for this Inline sample functionality is a bit confusing and should perhaps be deleted as it suggests there is a separate template file.
Again, thank you for your help and your work. I'm closing this issue. Take care,
Bravo ! This solved my problem. Thanks so much.
If I may suggest, perhaps the "Template File" section in the documentation for this Inline sample functionality is a bit confusing and should perhaps be deleted as it suggests there is a separate template file.
Again, thank you for your help and your work. I'm closing this issue. Take care,
There are 2 ways to use the directive. It is possible to use a separate file using the :template:
parameter to the directive, or to have an inline template using the body as you're doing here.
Bravo ! This solved my problem. Thanks so much.
If I may suggest, perhaps the "Template File" section in the documentation for this Inline sample functionality is a bit confusing and should perhaps be deleted as it suggests there is a separate template file.
Again, thank you for your help and your work. I'm closing this issue. Take care,There are 2 ways to use the directive. It is possible to use a separate file using the
:template:
parameter to the directive, or to have an inline template using the body as you're doing here.
I understand what you mean.
In the JSON sample, https://sphinxcontribdatatemplates.readthedocs.io/en/latest/json.html "the template file" section is actually used, but in the Inline sample https://sphinxcontribdatatemplates.readthedocs.io/en/latest/inline.html "the template file" though indicated on the page is not used.
It is possible to use a separate file using the :template: parameter to the directive, or to have an inline template using the body as you're doing here.
is it true for any format (CSV, XML as well)? it seems this is specific to JSON.
If it is true for all format, I think a simple passage with your sentence, the data file and the rst file would be nice. (without the "template file" section)
Bye !
Ah, I see what you mean.
Yes, it is possible to use the inline or file templates with any format. We have 1 example using JSON. I made some changes in #79 to clear that up. Please let me know what you think.
I think it is almost perfect :) I would just simply:
- erase the mention to JSON in the global title of the rst file since it works for all format. Replacing "Inline Sample (JSON)" by "Inline Sample". You can if you want to mention JSON as an example, put it in parentheses after the "Data file" and "Loading the template" titles
- Replace "Loading the template" title with something like "Rst file example". The term "loading" usually refers to loading a file, or something external to the file being considerd (RST file), which is not the case and might a bit be confusing,
But these are humble suggestions :)