{"id":37843,"date":"2015-07-28T08:50:48","date_gmt":"2015-07-28T08:50:48","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/twig-anything-csv\/"},"modified":"2015-08-14T11:37:59","modified_gmt":"2015-08-14T11:37:59","slug":"twig-anything-csv","status":"publish","type":"plugin","link":"https:\/\/es-cr.wordpress.org\/plugins\/twig-anything-csv\/","author":5714238,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.1","stable_tag":"trunk","tested":"4.2.39","requires":"3.6.1","requires_php":"","requires_plugins":"","header_name":"CSV Format","header_author":"Anton Andriievskyi","header_description":"","assets_banners_color":"bfccb5","last_updated":"2015-08-14 11:37:59","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/twiganything.com\/csv-format","header_author_uri":"https:\/\/twiganything.com\/author","rating":0,"author_block_rating":0,"active_installs":10,"downloads":2056,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":[],"upgrade_notice":{"1.1":"<p>This version adds a link to Community and Support forum for your convenience. It also checks if Twig Anything plugin is active and installed, and shows a notice if it is not. This is not a critical update.<\/p>"},"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":"1208691","resolution":"772x250","location":"assets"}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":"1208086","resolution":"1","location":"assets"},"screenshot-2.png":{"filename":"screenshot-2.png","revision":"1208086","resolution":"2","location":"assets"},"screenshot-3.png":{"filename":"screenshot-3.png","revision":"1208086","resolution":"3","location":"assets"}},"screenshots":{"1":"The slick Data Source settings panel with CSV format selected and custom format configuration fields: Delimiter character, Enclosure character and Escape character.","2":"An example of CSV format in action: a CSV file with country names and their corresponding top-level domain names is parsed, and then only countries that start with \"D\" are displayed.","3":"A Twig Template that uses CSV data and outputs an example shown on the previous screenshot."},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[62061,62063,567,62058,6590],"plugin_category":[],"plugin_contributors":[90977],"plugin_business_model":[],"class_list":["post-37843","plugin","type-plugin","status-publish","hentry","plugin_tags-comma-separated-values","plugin_tags-comma-separated","plugin_tags-csv","plugin_tags-csv-api","plugin_tags-excel","plugin_contributors-meglio","plugin_committers-meglio"],"banners":{"banner":"https:\/\/ps.w.org\/twig-anything-csv\/assets\/banner-772x250.png?rev=1208691","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/twig-anything-csv_bfccb5.svg","icon_2x":false,"generated":true},"screenshots":[{"src":"https:\/\/ps.w.org\/twig-anything-csv\/assets\/screenshot-1.png?rev=1208086","caption":"The slick Data Source settings panel with CSV format selected and custom format configuration fields: Delimiter character, Enclosure character and Escape character."},{"src":"https:\/\/ps.w.org\/twig-anything-csv\/assets\/screenshot-2.png?rev=1208086","caption":"An example of CSV format in action: a CSV file with country names and their corresponding top-level domain names is parsed, and then only countries that start with \"D\" are displayed."},{"src":"https:\/\/ps.w.org\/twig-anything-csv\/assets\/screenshot-3.png?rev=1208086","caption":"A Twig Template that uses CSV data and outputs an example shown on the previous screenshot."}],"raw_content":"<!--section=description-->\n<p>Read CSV data from local files, WordPres media files, local or remote databases or 3rd party API, and output it anywhere in WordPress with using shortcodes, in posts\/pages, headers\/footers, widgets or in Visual Composer.<\/p>\n\n<p>You can configure how CSV is parsed by specifying delimiter character, enclosure character and escape character.<\/p>\n\n<p><em>This is a free add-on that adds CSV support (comma-separated values) to the\n<a href=\"https:\/\/twiganything.com\/\" title=\"Twig Anything\">Twig Anything<\/a> WordPress plugin.<\/em><\/p>\n\n<p>Tutorials below demonstrate 3 examples:<\/p>\n\n<ul>\n<li>Example 1: generate text, one line for each line from CSV<\/li>\n<li>Example 2: generate a table<\/li>\n<li>Example 3: use shortcodes to output CSV anywhere in WordPress<\/li>\n<\/ul>\n\n<h4>EXAMPLE 1: MULTILINE TEXT<\/h4>\n\n<p>Let us use a CSV file with a list of countries and their corresponding top-level domain names (TLD). Here is an extract from the file:<\/p>\n\n<pre><code>Belgium,Brussels,EUR,Euro,BE,.be\nBelize,Belmopan,BZD,Dollar,BZ,.bz\nBenin,Porto-Novo,XOF,Franc,BJ,.bj\nBhutan,Thimphu,BTN,Ngultrum,BT,.bt\n<\/code><\/pre>\n\n<p>In our example, let's display TLDs for all countries that start with \u201cD\u201d:<\/p>\n\n<pre><code>Denmark - .dk\nDjibouti - .dj\nDominica - .dm\nDominican Republic - .do\n<\/code><\/pre>\n\n<p>Columns are numbered starting from #0, so we will need the column #0 (country name) and #5 (top-level domain name).<\/p>\n\n<p>After the CSV input has been parsed, the resulting lines are passed to your Twig Template as the <strong>data<\/strong> variable. You can then loop over it with using <a href=\"http:\/\/twig.sensiolabs.org\/doc\/tags\/for.html\">\u201cfor\u201d syntax:<\/a>:<\/p>\n\n<pre><code>{% for row in data if row.0|slice(0,1)|upper == 'D' %}\n  {{ row.0 }} - &lt;strong&gt;{{row.5}}&lt;\/strong&gt;&lt;br\/&gt;\n{% endfor %}\n\n{% for row in data %}...{% endfor %} is the loop. The code inside the loop will be rendered once for every line from the CSV file.\n<\/code><\/pre>\n\n<p>Let us take a closer look at this piece: <code>if row.0|slice(0,1)|upper == 'D'<\/code><\/p>\n\n<p>First of all, <code>row.0<\/code> is how we access column #0, a country name in our case. Next, <code>|slice(0,1)<\/code> is a Twig filter that takes the first character of the country name. The next filter is <code>|upper<\/code> and it simply uppercases the first letter returned by the previous filter. Finally, we only allow for countries that start with the \u201cD\u201d letter: <code>== 'D'<\/code>.<\/p>\n\n<p>Inside the loop, we output a country name with using <code>{{row.0}}<\/code> and a TLD name with using <code>{{row.5}}<\/code>. Plus a very basic HTML markup: <code>&lt;br\/&gt;<\/code> to insert a line break and <code>&lt;strong&gt;...&lt;\/strong&gt;<\/code> to make TLD name appear bold.<\/p>\n\n<h4>EXAMPLE 2: TABLE<\/h4>\n\n<p>Using the same CSV file, let's now output our data in a table with using HTML markup.<\/p>\n\n<p>If you are not very familiar with HTML, I recommend going through the following tutorials - you'll learn in 10 minutes, I guarantee!<\/p>\n\n<ul>\n<li><a href=\"https:\/\/computerservices.temple.edu\/creating-tables-html\">Tutorial 1<\/a><\/li>\n<li><a href=\"https:\/\/css-tricks.com\/complete-guide-table-element\/\">Tutorial 2<\/a><\/li>\n<\/ul>\n\n<p>You can also use the following table generators and just copy-paste the HTML they generate right into your template. The generators also allow to apply some basic styling, like borders, colors, margins, paddings etc.<\/p>\n\n<ul>\n<li><a href=\"http:\/\/www.rapidtables.com\/web\/tools\/html-table-generator.htm\">Generator 1<\/a><\/li>\n<li><a href=\"http:\/\/www.textfixer.com\/html\/html-table-generator.php\">Generator 2<\/a><\/li>\n<\/ul>\n\n<p>So, we will use the following HTML tags:<\/p>\n\n<ul>\n<li><code>&lt;table&gt;...&lt;\/table&gt;<\/code> to make a table<\/li>\n<li><code>&lt;thead&gt;...&lt;\/thead&gt;<\/code> to make a table header with column headings<\/li>\n<li><code>&lt;tbody&gt;...&lt;\/tbody&gt;<\/code> to make a table body with all the rows from CSV<\/li>\n<li><code>&lt;tr&gt;...&lt;\/tr&gt;<\/code> to make a table row<\/li>\n<li><code>&lt;th&gt;...&lt;\/th&gt;<\/code> to make a cell in the header's row<\/li>\n<li><code>&lt;td&gt;...&lt;\/td&gt;<\/code> to make a cell in a regular rows in the table's body<\/li>\n<\/ul>\n\n<p>Here is our template:<\/p>\n\n<pre><code>&lt;table&gt;\n  &lt;thead&gt;\n    &lt;tr&gt;\n      &lt;th&gt;Country&lt;\/th&gt;\n      &lt;th&gt;TLD&lt;\/th&gt;\n    &lt;\/tr&gt;\n  &lt;\/thead&gt;\n  &lt;tbody&gt;\n  {% for row in data if row.0|slice(0,1)|upper == 'D' %}\n  &lt;tr&gt;\n    &lt;td&gt;{{ row.0 }}&lt;\/td&gt;\n    &lt;td&gt;{{ row.5 }}&lt;\/td&gt;\n  &lt;\/tr&gt;\n  {% endfor %}\n  &lt;\/tbody&gt;\n&lt;\/table&gt;\n<\/code><\/pre>\n\n<p>Notice how we use the <code>{% for row in data %}<\/code> syntax to loop over CSV lines,\nand then output a table row <code>&lt;tr&gt;...&lt;\/tr&gt;<\/code> inside the loop, so that\na new row is made for every CSV line.<\/p>\n\n<p>Actually, you can use just any HTML and stylize your table the way you need.\nJust don't forget to put <code>{{row.0}}<\/code>, <code>{{row.1}}<\/code> etc where you want\nyour csv values in the cells <code>&lt;td&gt;...&lt;\/td&gt;<\/code>.<\/p>\n\n<h4>EXAMPLE 3: SHORTCODES<\/h4>\n\n<p>While you prepare your template, you usually preview it many times by clicking\nthe \"Preview Changes\" button. Once you are happy with the preview, you will\nwant to embed it somewhere - in a post or a page, footer \/ header,\nin a widget or as a Visual Composer block.<\/p>\n\n<p>To embed your template, you will use a shortcode:<\/p>\n\n<pre><code>[twig-anything slug=\"my-template-slug\"]\n<\/code><\/pre>\n\n<p>In WordPress, every Twig Template has its own slug, just like posts and pages.\nIt can be found under the template title.<\/p>\n\n<p>Alternatively, you can use the template ID:<\/p>\n\n<pre><code>[twig-anything id=\"123\"]\n<\/code><\/pre>\n\n<!--section=installation-->\n<h4>Minimum Requirements<\/h4>\n\n<ul>\n<li>WordPress 3.6.1 or greater<\/li>\n<li>PHP version 5.4 or greater<\/li>\n<li>MySQL version 5.0 or greater<\/li>\n<li><a href=\"https:\/\/twiganything.com\">Twig Anything<\/a> WordPress plugin version 1.3 or greater<\/li>\n<\/ul>\n\n<h4>Automatic installation<\/h4>\n\n<p>Automatic installation is the easiest option as WordPress handles the file transfers itself and you don\u2019t need to leave your web browser. To do an automatic install of Twig Anything CSV, log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.<\/p>\n\n<p>In the search field type \u201cTwig Anything CSV\u201d and click Search Plugins. Once you\u2019ve found the plugin, you can view details about it such as the the point release, rating and description. Most importantly, of course, you can install it by simply clicking \u201cInstall Now\u201d.<\/p>\n\n<h4>Manual installation<\/h4>\n\n<p>The manual installation method involves downloading our CSV (comma separated values) format plugin and uploading it to your webserver via your favourite FTP application. The WordPress codex contains <a href=\"http:\/\/codex.wordpress.org\/Managing_Plugins#Manual_Plugin_Installation\">instructions on how to do this here<\/a>.<\/p>\n\n<h4>Updating<\/h4>\n\n<p>Automatic updates should work like a charm; as always though, ensure you backup your site just in case.<\/p>\n\n<ol>\n<li>Upload <code>twig-anything-csv.zip<\/code> to the <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt>From where can it fetch CSV data?<\/dt>\n<dd><p>Because this is an add-on for the\n<a href=\"https:\/\/twiganything.com\">Twig Anything<\/a> WordPress plugin,\nit can fetch your CSV input from various sources: a local file,\na URL, a MySQL database (out of the box) and many more\nwith custom data source add-ons.<\/p><\/dd>\n<dt>Can I configure the field delimiter character?<\/dt>\n<dd><p><strong>Yes<\/strong>, you can specify any delimiter character (one character only).<\/p>\n\n<p>If you want to use <code>TAB<\/code> as the delimiter, input <code>\\t<\/code>\nin the <em>Delimiter Character<\/em> setting.<\/p>\n\n<p>By default, the delimiter character is set to a comma \"<strong>,<\/strong>\".<\/p><\/dd>\n<dt>Can I configure the enclosure character?<\/dt>\n<dd><p><strong>Yes<\/strong>, you can specify any enclosure character (one character only).<\/p>\n\n<p>By default, its value is double-quotes <strong>\"<\/strong><\/p><\/dd>\n<dt>Can I configure the field escape character?<\/dt>\n<dd><p><strong>Yes<\/strong>, you can specify any escape character (one character only).<\/p>\n\n<p>By default, its value is a backslash \"<strong>&#092;<\/strong>\"<\/p><\/dd>\n<dt>How to loop through the parsed CSV lines<\/dt>\n<dd><p>In your Twig Anything template, use the Twig's <a href=\"http:\/\/twig.sensiolabs.org\/doc\/tags\/for.html\">\"for\" syntax<\/a>.\nFor example:<\/p>\n\n<pre><code>{% for row in data %}\n  Text in the first column: {{row.0}},\n  Text in the third column: {{row.2}} &lt;br\/&gt;\n{% endfor %}\n<\/code><\/pre>\n\n<p>Note that the the sequence of all CSV lines is always passed to your template as <strong>data<\/strong> variable\nand in the same order as it appears in the parsed data source (e.g. a .csv file).<\/p><\/dd>\n<dt>How to access individual columns<\/dt>\n<dd><p>Columns are indexed starting from 0, so to access the content of the first column,\nuse <code>{{row.0}}<\/code>; for the second column, use <code>{{row.1}}<\/code> and so forth.<\/p><\/dd>\n<dt>How to filter CSV rows by a particular column<\/dt>\n<dd><p>Add <a href=\"http:\/\/twig.sensiolabs.org\/doc\/tags\/for.html#adding-a-condition\">a condition<\/a> to your loop.\nFor example, if a country name is stored in the second column (column #1),\n and you want to only show entries where the country name starts with D:<\/p>\n\n<pre><code>{% for row in data if row.1|slice(0,1)|upper == 'D' %}\n  {{ row.1 }}&lt;br\/&gt;\n{% endfor %}\n<\/code><\/pre>\n\n<p>In this example, <code>|slice(0,1)<\/code> is a filter that extracts the first letter; <code>|upper<\/code> is another filter that uppercases that letter. Finally, we only output what is inside the loop if the letter is <strong>D<\/strong>: <code>if row.1|slice(0,1)|upper == 'D'<\/code>.<\/p><\/dd>\n<dt>How does it parse my CSV?<\/dt>\n<dd><p>Internally, the <a href=\"http:\/\/php.net\/manual\/en\/function.str-getcsv.php\"><code>str-getcsv()<\/code><\/a>\nPHP function is used. It parses a CSV string into an array. A sequence\nof such arrays is then passed to your template as the <code>data<\/code> variable,\nso you can loop over it.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>1.1<\/h4>\n\n<ul>\n<li>Add link to Community and Support forum to the Plugins list page<\/li>\n<li>Check if Twig Anything is installed and active, show a notice if it is not<\/li>\n<\/ul>\n\n<h4>1.0<\/h4>\n\n<ul>\n<li>The first release<\/li>\n<\/ul>","raw_excerpt":"Read CSV data from local files, WordPres media files, local or remote databases or 3rd party API, and output it anywhere in WordPress with using short &hellip;","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/37843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=37843"}],"author":[{"embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/meglio"}],"wp:attachment":[{"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=37843"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=37843"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=37843"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=37843"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=37843"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/es-cr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=37843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}