Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifying render() to prevent recursion? #163

Open
mmilano opened this issue Apr 2, 2018 · 2 comments
Open

modifying render() to prevent recursion? #163

mmilano opened this issue Apr 2, 2018 · 2 comments

Comments

@mmilano
Copy link
Contributor

mmilano commented Apr 2, 2018

modification assistance request:
Are there any suggestions about how to modify panini.render() to

  1. allow a page content template (page.html) to include itself i.e. {{> body}}
  2. but prevent infinite recursive rendering.

right now, that will result in a render loop.

advice?

or, alternatively, a way to access the rendered body - the var page in render() or better yet, the partial 'body' - from other helpers?

@gakimball
Copy link
Contributor

What do you need this for?

@mmilano
Copy link
Contributor Author

mmilano commented Apr 3, 2018

well....since you asked...
there are actually a couple of directions stuffed into the question.

context:

  • static site being generated
  • node environment,
  • gulp for building tasks,
  • mostly the regular panini 1.6x.
  • each page has it's own file nameOfThePage.html
  • using a layout layout-page.html, which includes a couple of custom partials as well as {{> body}}

Ultimately, i am attempting to build a helper that parses the page's body content and generates a table of contents for the page. Call the helper toc.js.

The process i am working with is:

  1. get the generated page content (which itself might include html, markup, partials, and helpers)
  2. extract headings (to a desired depth), and
  3. output the html for the table of contents (as page navigation via anchor links)

#3 i can do, once i have an array or object of headings. That depends on…

#2 i hope to do with the help of cheerio.js. doing this depends on…

#1.

i experimented with adding the body content with in the nameOfThePage.html page.
infinite render loop. node crashes. makes a certain sense, if it is not checked internally.

i tried making toc.js a block helper in the layout-page, with {{> body}} as the block content, like so:

{{#toc}}
{{> body}}
{{/toc}}

but that isn't really the right spirit of how it should work.

I considered adding the page to the pageData object, but that feels needlessly bloated.

Ive tried accessing panini itself, and getting the body content. I can get part-way, but it is the raw content - pre-rendering - and I cant figure out how to get it post-rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants