1

I successfully imported my tumblr blog with the amazing Feedme plugin over the rss feed of the blog. The plugin creates posts and feeds the "title", "date", "tag" and of course the "content" inside my craft and I can assign a field to each of those elements.

Here is the thing: The images in tumblr are included in the content. Feedme isnt able to crawl for img tags and make an asset out of it in craft. So the images are still on tumblr and are just linked in the html:

für Hotels und Gastronomie.</p>
<figure data-orig-width="1080" data-orig-height="568" class="tmblr-full"><img src="http://68.media.tumblr.com/09fe97556d12eb488c91da31c71f44d5/tumblr_inline_ot0whuvZ6y1rft7f2_540.png" title="Online-to-offline Kundenreise" alt="blog bild lokale customer journey" data-orig-width="1080" data-orig-height="568"></figure>

Does anyone have an idea how I can get the first image in my template? the prettiest solution would be of course if I find a way to make it an asset. But if not, it would be nice if I could crawl the html content for img tags and get the link to the image on the tumblr server......

  • Could be some with a custom PHP script/Craft plugin. Are you comfortable with that? – Brad Bell Jul 17 '17 at 16:56
  • This is indeed a bit of a tricky thing at the moment, in that Feed Me won't auto-extract inline image data. This could be fixed by a custom PHP script to extract the content out. We've done this many times, so feel free to get in touch if you would like assistance. – crawf Jul 23 '17 at 14:36
  • @crawf I would like to contact you, but I dont know how to write pm in this forum? sorry, I am pretty new here... – Jan Jul 24 '17 at 19:55
  • @Jan Hit me up on the Craft Slack channel, handle crawf – crawf Jul 26 '17 at 5:28
1

I know this is of course not an elegant solution, but it works for now. I used twig filters to extract url and alt tag of the image.

<div class="blog-post-featured-image">
            {% if entry.featuredImage|length %}
                {{ snippets.image( entry.featuredImage.first(),entry.url )}}
            {% else %} {# For the tumblr imports, extract first image #}
                {# Extract the src #}
                {% set spliter = entry.articleBody.type('text').first().text|split('src="') %}
                {% set spliter = spliter[1]|split('"') %}
                {% set firstTumblrImage = spliter[0] %}

                {# Extract the alt-Tag of the Featured Image#}
                {% set spliter = entry.articleBody.type('text').first().text|split('alt="') %}
                {% set spliter = spliter[1]|split('"') %}
                {% set imageAltTag = spliter[0] %}
                    <a href="{{ entry.url }}"><img src="{{ firstTumblrImage }}" alt="{{ imageAltTag }}"></a>
            {% endif %}
        </div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.