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

datapage_url usage throwing undefined method `tr' #85

Open
sahilk opened this issue Sep 19, 2020 · 2 comments
Open

datapage_url usage throwing undefined method `tr' #85

sahilk opened this issue Sep 19, 2020 · 2 comments
Labels

Comments

@sahilk
Copy link

sahilk commented Sep 19, 2020

Not sure if I'm using it correctly. {{ page_name | datapage_url: dir }} is mentioned in the docs for generating links to generated pages. I use name_expr in _config.yml to generate the files in an acts folder, so is {{ name_expr | datapage_url: acts }} the right way to do this?

Liquid Exception: undefined method `tr' for nil:NilClass in index.html
Error: undefined method `tr' for nil:NilClass

Would you like to see the --trace output as well?

(Sorry, but I'm also not entirely clear on how to use this liquid tag in my template to generate links for each of the items from the data file.)

As a fallback, I'm currently using slugify to create the page URLs manually, which works just fine, but raising this here to be sure if I'm doing something wrong or if there's a bug.

@avillafiorita
Copy link
Owner

Hi, it is indeed a bug, datapage_url is not able to manage name_expr. Thanks for reporting, I will look into it.

To give a bit of context, datapage_url has not been updated for a while and, in particular, it is not "aware" of name_expr.

@avillafiorita
Copy link
Owner

Problem: the value of name_expr cannot be directly used in Liquid.

To generate the link, therefore, we need to:

  1. find the record for which we want to generate the URL (this requires an id for the record and the name of the data file in which the record is stored)
  2. get the data for the record (yaml)
  3. check the configuration for the data file and generate the link according to it (e.g., by looking at page_gen and applying the appropriate piece of code to data; that is, getting name or executing name_expr)

Current syntax of datapage_url is inadequate. Proposal for new syntax:

{{ <unique_identifier> | datapage_url_for: }}

where:

<unique_identifier> is a unique identifier of the record for which we want to generate the URL. It should probably be the value assigned to the name field in the record (even if name_expr is used). [Alternatively, a new key, id, has to be added to the configuration.]

is the name of the data structure (= data file) to which the record belongs. The name of the data is needed to

  1. read the appropriate specification in page_gen
  2. read the content of the record (for instance to apply name_expr)

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

No branches or pull requests

2 participants