Someone interested in Airtable integration plugin?


#1

I wrote a plugin that pulls data from Airtable and passes it to Twig as variables. If someone is interested in actually using and/or developing it further, I will add it to Git.


#2

Sounds God. Do you have an example to look at?


#3

I would love to see this. I use airtable for everything. If you shared i would be grateful!


#4

It works via Twig extension, which then makes the Airtable’s field values availbale as {{ myAirtableField }} in Twig templates. The way I built it now is that you can map a Twig template to a Airtable table, then on the page using this template you set the ID of the record from Airtable like this:
record_id: BlaBlaRecordID

and the plugin searches for the according record. So it is quite flexible, at least for what we are building.

Below is the meat of my current code. At this stage with some hardocoded stuff, but if there is interest, I can improve it to be generic to be used by many people.

…it is amazing how fast you can code such stuff, considering I only started with Grav few days ago and I am not a PHP developer (.NET).

If you like I can share all the code with you already now, but as I said, it is hardcoded to our business right now.

private $template2tableMap = array(
			'venue'		=> array('SuppliersVenues', 'VenueID'),
			'wedding' 	=> array('Clients', '____needToSet_______')
);

private $record;

private function init()
{
	$this->grav = Grav::instance();
	$grav = $this->grav;
	$pageHeader = $grav['page']->header();
	
	$this->airtable = new Airtable($this->airtableConfig);
	
	// each Grav template is associated with one Airtable table and name of the ID field
	$template = $grav['page']->template();
	$tableInfo = $this->template2tableMap[$template];
	
	$params = array(
		"filterByFormula" => "AND( ".$tableInfo[1]." = '".$pageHeader->record_id."' )"
	);

	$request = $this->airtable->getContent($tableInfo[0], $params);
	$response = $request->getResponse();
	$this->record = $response['records'][0]->fields;
}

public function getName()
{
	return 'AirtableTwigExtension';
}
public function getFunctions()
{
	return [
		new \Twig_SimpleFunction('venueName', [$this, 'venueName']),
		new \Twig_SimpleFunction('venueDescription', [$this, 'venueDescription']),
		
	];
}
public function venueName()
{
	$this->init();
	return $this->record->Name;
}

public function venueDescription()
{
	$this->init();
	return $this->record->Description;
}

#5

I would be interested in a such a Twig Airtable - Grav integration plugin.

Could you link to your Git repo?


#6

It is still a bit too raw and in a few places hardcoded to our business, but I am working on it. You will be able to map each Grav template to an Airtable table, then all you need to do is on the page set the record ID value in the header (frontmatter) and all the fields from Airtable will be available as {{ record.MyAirtableField }} in your Twig template!

Are you a developer?


#7

Hi - I’d be interested in this and/or the same for Smartsheet. Thanks


#8

Quick update. I have now two versions: async and real-time. For our project we will go with the async one, which is basically a stand-alone PHP (maybe will port it to Gulp) script that pulls the data from Airtable and creates an .md file for each record with fields as YAML Frontmatter. So it is decoupled from the Airtable API at run-time, which is faster and more robust compared to calling the API on every HTTP request (even if it is cached). So this script is not really a Grav plugin now, but I could still warp it as plugin to allow for example to map Airtable tables to Grav templates.

No sure if I will continue with the real-time version, as it kind of goes against Grav idea. But there might be use cases in future where we probably need to pull real-time data from Airtable.

…and I learned how to use GitHub / Git. Yay.


#9

Hi @Waldemar I am very interested in the plugin. Thx!


#10

Thanks for showing interest. I keep developing it for our project, but so far there is not much hard-coded stuff.