fractal icon indicating copy to clipboard operation
fractal copied to clipboard

Linking to other components

Open pete-hotchkiss opened this issue 8 years ago • 18 comments

I could be completely missing this in the documentation, but I can't see where there is a way to have handlebars / MD in a components notes file render a link to another component.

i.e.

This is a description of how this component works. But it's also
similar to {{ components.buttons.cancel-button }}  

Am I just being blind/dumb ?

pete-hotchkiss avatar Aug 17 '16 09:08 pete-hotchkiss

No not blind or dumb... but because it's actually a theme's job to specify what URLs are available it's a little tricky to provide a way to handle this that still works if people use a different theme from the default.

At the moment I handle this with a custom handlebars helper, and eventually I'll get round to adding some more default helpers in to make stuff like this easier in documentation pages.

For the default theme, the component URLs always take the form of:

  • Component detail page: /components/detail/handle
  • Component preview page: /components/preview/handle
  • Component rendered without preview layout: /components/preview/handle

so you could create a helper that looks something like this:

const Handlebars = require('handlebars'); // note you need to `npm i --save handlebars` first!

function linkTo(handle, view) {
    view = view || 'detail';
    return new Handlebars.SafeString(`/components/${view}/${handle.replace('@','')}`);
}

You obviously still need to register this with the handlebars template adapter but hopefully that will help somewhat?

allmarkedup avatar Aug 17 '16 10:08 allmarkedup

Trying to do something similar. A problem arises when generating a static html build of fractal, as all the paths should then have an .html extension. Any simple way to check that?

mihkeleidast avatar Oct 05 '16 18:10 mihkeleidast

@risker I’m also having the same issue as you. Bummer.

isellsoap avatar Feb 26 '18 12:02 isellsoap

I ended up doing <a href="{% if frctl.env.server %}/components/detail/logo{% else %}/components/detail/logo.html{% endif %}" > It's mucky and it won't work in the markdown though...

matt-tyas avatar Jun 07 '18 14:06 matt-tyas

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 06 '18 14:08 stale[bot]

Trying to do something similar. A problem arises when generating a static html build of fractal, as all the paths should then have an .html extension. Any simple way to check that?

@risker my team uses 2 fractal configuration files, one for dev server and one for dist build. I think you can use similar approach and use different handlebars instances with helpers logic.

tlenex avatar Aug 07 '18 22:08 tlenex

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 06 '18 22:10 stale[bot]

If that is of any help, I have this Nunjucks helper:

    link(handle) {
      const name = handle.replace('@', '');
      let prefix = '';
      let ext = '';

      if (process.env.NODE_ENV === 'production') {
        prefix = '../..';
        ext = '.html';
      }

      return `<a href="${prefix}/components/detail/${name}${ext}">${handle}</a>`;
    },

Which then allows me to link to other components with: {{ '@handle' | link }}.

Notice that I run my Fractal commands prefixed with NODE_ENV=[development|production] for this to work properly.

LeBenLeBen avatar Oct 07 '18 08:10 LeBenLeBen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 06 '18 09:12 stale[bot]

Trying to do something similar. A problem arises when generating a static html build of fractal, as all the paths should then have an .html extension. Any simple way to check that?

any updates on this? I see the link to https://github.com/frctl/fractal/issues/197 but then I lose track if this particular issue has been solved.

I'd like a way to be able to link to a component in fractal (inside a changelog.md file) that works for both development and static build scenarios.

Thanks for any help!

johnstonian avatar Jul 23 '19 21:07 johnstonian

Reopening since this is something we should figure out with integrating core/theme/adapter somehow.

I see the need for three usecases:

  • linking from component templates (this should be implemented by a helper in adapter)
  • linking from docs pages - same as component template
  • adding links to context from the config file. sometimes we need to statically link together two view templates, for example, without using helpers in templates, since the url/href should be a simple context value.

mihkeleidast avatar May 02 '20 12:05 mihkeleidast

@mihkeleidast It sounds like this hasn't been solved and there's no workaround in regards to markdown files. Is that correct? We're looking to link many of our components back to one of the documentation pages for reference.

dartanian300 avatar Jun 03 '20 14:06 dartanian300

@dartanian300 the issue is open, so there is no official solution. you can still work around it by creating your own template helper and using that.

mihkeleidast avatar Jun 04 '20 11:06 mihkeleidast

@mihkeleidast I'm a bit new to Fractal so I could be misunderstanding, but that would only work for components, right? Can I use that in markdown for the notes section?

dartanian300 avatar Jun 04 '20 12:06 dartanian300

Please read the docs: https://fractal.build/guide/documentation/dynamic-docs.html

mihkeleidast avatar Jun 04 '20 12:06 mihkeleidast

That page should probably be updated to note that the same configuration can be made in the Notes. As is, it appears that you can only do so in the Documentation pages. It's not fully clear for someone new to Fractal.

dartanian300 avatar Jun 11 '20 14:06 dartanian300

It's also documented under the component notes section: https://fractal.build/guide/components/notes.html#the-readme-md-file

If you think the docs can be improved, PRs are welcome.

mihkeleidast avatar Jun 11 '20 18:06 mihkeleidast

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 16 '20 07:08 stale[bot]