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

Retrieving an image as a directive #18

Closed
vergarm opened this issue Aug 2, 2016 · 5 comments
Closed

Retrieving an image as a directive #18

vergarm opened this issue Aug 2, 2016 · 5 comments

Comments

@vergarm
Copy link

vergarm commented Aug 2, 2016

@jvandemo - is it possible to retrieve an image from contentful as a directive or do i have to use the service for that? Thanks!

<img contentful-entry="'6KntaYXaHSyIw8M6eo26OK'" src="$contentfulEntry.fields.url"/>

@jvandemo
Copy link
Owner

jvandemo commented Aug 6, 2016

@vergarm — You can access an image right from the Contentful data indeed, e.g.:

<ul contentful-entries="content_type=dog">
  <li ng-repeat="dog in $contentfulEntries.items | orderBy:'fields.name' ">
    <h1>{{ dog.fields.name }}</h2>
    <img ng-src="{{ dog.fields.image.fields.file.url }}" />
  </li>
</ul>

@vergarm
Copy link
Author

vergarm commented Oct 20, 2016

@jvandemo - can i access the image without looping?
like this:
<img contentful-asset="'6KntaYXaHSyIw8M6eo26OK'" ng-src="$contentfulEntry.image.fields.url"/>``

@jvandemo
Copy link
Owner

jvandemo commented Oct 22, 2016

@vergarm — Yes, you should be able to do something like:

<div contentful-entry="'6KntaYXaHSyIw8M6eo26OK'">
  <img src="{{ $contentfulEntry.fields.image.fields.file.url}}"
</div>

where image is the name of the field in your Contentful entry. So if you have an image field called avatar, this would be something like:

<div contentful-entry="'6KntaYXaHSyIw8M6eo26OK'">
  <img src="{{ $contentfulEntry.fields.avatar.fields.file.url}}"
</div>

Does that make sense? Thanks!

@vergarm
Copy link
Author

vergarm commented Oct 24, 2016

Thanks! that worked :-)

@jvandemo
Copy link
Owner

@vergarm — Super, thank you for the confirmation.

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